You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use userManager.CreateIdentityAsync method, but I get a NRE everytime.
After debugging the code for AspNetIdentity, I have noticed that the NRE was thrown when calling CreateAsync in ClaimsIdentityFactory class method.
More precisely, the exception is thrown when iterating over the list of roles, but in my particular case it is null and so it throws. I have added a comment in the code to indicate exactly where the exception is thrown:
/// <summary>/// Create a ClaimsIdentity from a user/// </summary>/// <param name="manager"></param>/// <param name="user"></param>/// <param name="authenticationType"></param>/// <returns></returns>publicvirtualasyncTask<ClaimsIdentity>CreateAsync(UserManager<TUser,TKey>manager,TUseruser,stringauthenticationType){if(manager==null){thrownewArgumentNullException("manager");}if(user==null){thrownewArgumentNullException("user");}varid=newClaimsIdentity(authenticationType,UserNameClaimType,RoleClaimType);id.AddClaim(newClaim(UserIdClaimType,ConvertIdToString(user.Id),ClaimValueTypes.String));id.AddClaim(newClaim(UserNameClaimType,user.UserName,ClaimValueTypes.String));id.AddClaim(newClaim(IdentityProviderClaimType,DefaultIdentityProviderClaimValue,ClaimValueTypes.String));if(manager.SupportsUserSecurityStamp){id.AddClaim(newClaim(SecurityStampClaimType,awaitmanager.GetSecurityStampAsync(user.Id).WithCurrentCulture()));}if(manager.SupportsUserRole){IList<string>roles=awaitmanager.GetRolesAsync(user.Id).WithCurrentCulture();// <-- roles is nullforeach(stringroleNameinroles)// <-- NRE thrown here{id.AddClaim(newClaim(RoleClaimType,roleName,ClaimValueTypes.String));}}if(manager.SupportsUserClaim){id.AddClaims(awaitmanager.GetClaimsAsync(user.Id).WithCurrentCulture());}returnid;}
I am not sure why the list of roles is null though. Is this bug or is there something I am missing there? Thanks.
NuGet:
package: Microsoft.AspNet.Identity.Core
version: 2.2.1
The text was updated successfully, but these errors were encountered:
I am trying to use userManager.CreateIdentityAsync method, but I get a NRE everytime.
After debugging the code for AspNetIdentity, I have noticed that the NRE was thrown when calling CreateAsync in ClaimsIdentityFactory class method.
More precisely, the exception is thrown when iterating over the list of roles, but in my particular case it is
null
and so it throws. I have added a comment in the code to indicate exactly where the exception is thrown:I am not sure why the list of roles is
null
though. Is this bug or is there something I am missing there? Thanks.NuGet:
The text was updated successfully, but these errors were encountered: