User, Extended Users and Roles. Issue.

Topics: Troubleshooting
Feb 9, 2013 at 1:06 AM

I am getting this error a lot in the Error Log.
Orchard.ContentManagement.DefaultContentManager - NullReferenceException thrown from IContentHandler by Orchard.Roles.Handlers.UserRolesPartHandler System.NullReferenceException: Object reference not set to an instance of an object. at Orchard.Roles.Handlers.UserRolesPartHandler.<.ctor>b__1(UserRolesPartRecord x) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Orchard.Roles.Handlers.UserRolesPartHandler.<.ctor>b__0(LoadContentContext context, UserRolesPart userRoles) at Orchard.ContentManagement.Handlers.ContentHandler.Orchard.ContentManagement.Handlers.IContentHandler.Loaded(LoadContentContext context) in d:\wwwroot\\halo\Site\src\Orchard\ContentManagement\Handlers\ContentHandler.cs:line 238 at Orchard.InvokeExtensions.Invoke[TEvents](IEnumerable`1 events, Action`1 dispatch, ILogger logger) in d:\wwwroot\\halo\Site\src\Orchard\InvokeExtensions.cs:line 17 
This happens when a new Client User is created, although this new user is created correctly. The Client Users are extended Orchard Users.

The Handler of the Client Users has a ActivatingFilter to associate to the UserPart and to the Roles.
        public ClientUserPartHandler(IRepository<ClientUserPartRecord> repository) {
            Filters.Add(new ActivatingFilter<UserPart>(typeof(ClientUserPart).Name));
            Filters.Add(new ActivatingFilter<UserRolesPart>("Client_User"));
If some body could give a hand, I am kind of lost because I can seen the error.

Feb 18, 2013 at 12:04 PM
Found the error and fix it. Some users were created at some point but the UserRolesPart contains a null entry for Role Id. Sql Update those values and fixed.