I am facing a very peculiar problem while working with RoleManager of dotnet core.
I am getting a null value in the Role variable with the following code.
public IdentityRole Role { get; set; }
string id = "4de9af8e-c532-4d0a-8444-a63ffbd08ced";
Role = await _roleManager.FindByIdAsync(id);
However, it works fine when "role id" is provided directly to FindByIdAsync as shown below
Role = await _roleManager.FindByIdAsync("4de9af8e-c532-4d0a-8444-a63ffbd08ced");
Can anyone please help what can be the issue here? The same code has worked in different projects I worked on six months back.
I tried following
public IdentityRole Role { get; set; }
string id = "4de9af8e-c532-4d0a-8444-a63ffbd08ced";
Role = await _roleManager.FindByIdAsync(id);
Role is getting a null value whereas it should not have been null.
CodePudding user response:
Try following
Role = await _roleManager.FindByIdAsync(new Guid(id).ToString());