Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Moltzen-Bildsøe 15 posts 145 karma points
    Feb 04, 2021 @ 09:50
    Thomas Moltzen-Bilds√łe
    0

    After upgrade to Umbraco 7.15.5 - Parameter name: username - Value cannot be null or whitespace

    Hi

    We've upgraded about 40 sites from Umbraco 6.1.6 to Umbraco 7.15.5 (yes, we know about Umbraco 8 :)) and it worked great for all but one.

    We're getting a strange error, that we haven't seen before, see below.

    Anyone had problems with this?

    2021-02-04 10:42:34,617 [P1228/D58/T375] ERROR Umbraco.Web.Editors.ContentController - Unhandled controller exception occurred
    System.ArgumentException: Value cannot be null or whitespace.
    Parameter name: username
       at Umbraco.Core.Models.Membership.User..ctor(Int32 id, String name, String email, String username, String rawPasswordValue, IEnumerable`1 userGroups, Int32[] startContentIds, Int32[] startMediaIds)
       at Umbraco.Core.Persistence.Factories.UserFactory.BuildEntity(UserDto dto)
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
       at Umbraco.Core.Cache.DefaultRepositoryCachePolicy`2.GetAll(TId[] ids, Func`2 performGetAll)
       at Umbraco.Core.Persistence.Repositories.UserRepository.GetNextUsers(Int32 id, Int32 count)
       at Umbraco.Core.Services.UserService.GetNextUsers(Int32 id, Int32 count)
       at Umbraco.Core.Services.NotificationService.SendNotifications(IUser operatingUser, IEnumerable`1 entities, String action, String actionName, HttpContextBase http, Func`3 createSubject, Func`3 createBody)
       at Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService service, IUser sender, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext, ApplicationContext applicationContext)
       at Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext, ApplicationContext applicationContext)
       at Umbraco.Web.NotificationServiceExtensions.SendNotification(INotificationService service, IUmbracoEntity entity, IAction action, UmbracoContext umbracoContext)
       at Umbraco.Web.Strategies.NotificationsHandler.<>c__DisplayClass0_0.<ApplicationStarted>b__8(IUserService sender, SaveEventArgs`1 args)
       at Umbraco.Core.Events.TypedEventHandler`2.Invoke(TSender sender, TEventArgs e)
       at Umbraco.Core.Events.EventDefinition`2.RaiseEvent()
       at Umbraco.Core.Events.ScopeEventDispatcher.ScopeExitCompleted()
       at Umbraco.Core.Events.ScopeEventDispatcherBase.ScopeExit(Boolean completed)
       at Umbraco.Core.Scoping.Scope.<>c__DisplayClass70_0.<RobustExit>b__1()
       at Umbraco.Core.Scoping.Scope.TryFinally(Int32 index, Action[] actions)
       at Umbraco.Core.Scoping.Scope.TryFinally(Int32 index, Action[] actions)
       at Umbraco.Core.Scoping.Scope.RobustExit(Boolean completed, Boolean onException)
       at Umbraco.Core.Scoping.Scope.Dispose()
       at Umbraco.Core.Persistence.UnitOfWork.ScopeUnitOfWork.DisposeResources()
       at Umbraco.Core.DisposableObjectSlim.Dispose(Boolean disposing)
       at Umbraco.Core.DisposableObjectSlim.Dispose()
       at Umbraco.Core.Services.UserService.ReplaceUserGroupPermissions(Int32 groupId, IEnumerable`1 permissions, Int32[] entityIds)
       at Umbraco.Web.Editors.ContentController.PostSaveUserGroupPermissions(UserGroupPermissionsSave saveModel)
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
    

    Best Regards Thomas

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Feb 06, 2021 @ 11:12
    Marc Goodson
    0

    Hi Thomas

    Have a look in your umbracoUsers database table, do you somehow have a user in there with an empty username?

    If you follow the stack trace through, the source code, it starts after making changes to UserGroup permissions 'PostSaveUserGroupPermissions'

    https://github.com/umbraco/Umbraco-CMS/blob/e4e5e2d103b4f8ae93454c0b0ae088f3f7d1fc1b/src/Umbraco.Web/Editors/ContentController.cs#L160

    that calls UserService ReplaceUserGroupPermissions

    that, eventually dispatches an event called 'UserGroupPermissionsAssigned'

    https://github.com/umbraco/Umbraco-CMS/blob/0bd4dced0b3e9205660114406b7e814f817179c7/src/Umbraco.Core/Services/Implement/UserService.cs#L754

    that then is handled in a 'notification' class

    https://github.com/umbraco/Umbraco-CMS/blob/2bfef741914297c802bc6c77cc48780d7534f920/src/Umbraco.Web/Compose/NotificationsComponent.cs#L145

    Which then tries to get all the Users to notify, which eventually calls down to the repository level, to make a query via PetaPoco to the database:

    https://github.com/umbraco/Umbraco-CMS/blob/34e80d86e8c0b754f6b7a02e307f53cb32806bbe/src/Umbraco.Core/Persistence/Repositories/Implement/UserRepository.cs#L878

    var idsQuery = SqlContext.Sql()
            .Select<UserDto>(x => x.Id)
            .From<UserDto>()
            .Where<UserDto>(x => x.Id >= id)
            .OrderBy<UserDto>(x => x.Id);
    

    And then the raw SQL entity returned for each User 'UserDto' is used to build an Umbraco IUser object in the UserFactory: calling the 'BuildEntity' method:

    https://github.com/umbraco/Umbraco-CMS/blob/34e80d86e8c0b754f6b7a02e307f53cb32806bbe/src/Umbraco.Core/Persistence/Factories/UserFactory.cs#L10

    Which is the 'last error' in your trace, when constructing a new User object

     var user = new User(dto.Id, dto.UserName, dto.Email, dto.Login,dto.Password,
                    dto.UserGroupDtos.Select(x => x.ToReadOnlyGroup()).ToArray(),
                    dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Content).Select(x => x.StartNode).ToArray(),
                    dto.UserStartNodeDtos.Where(x => x.StartNodeType == (int)UserStartNodeDto.StartNodeTypeValue.Media).Select(x => x.StartNode).ToArray());
    

    And you can see, that for one of the Users that are affected by the group permissions change, and returned from the database via PetaPoco - it's UserName is empty... which throws the error....

    So I would, as I said earlier (blimey that seems a long time ago) - just check to see if any entries in the umbracoUsers table have a null entry or not - and manually update them via SQL to be 'something' - there might be more than one and I guess the other issue could be if a User was deleted from the umbracoUsers table but somehow are still linked to a particular userGroup - there is a table that maps users to user groups - so if it's not an obvious empty username, it will be worth querying that to see if any users are mapped to usergroups that no longer have an entry in the umbracoUsers table!

    regards

    marc

Please Sign in or register to post replies

Write your reply to:

Draft