Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value cannot be null error when using GenerateEmailConfirmationTokenAsync?

Tags:

I am using the following command:

var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

And I get the following error with stack trace:

    System.ArgumentNullException: Value cannot be null.
Parameter name: value
   at System.IO.BinaryWriter.Write(String value)
   at Microsoft.AspNetCore.Identity.DataProtectorTokenProvider`1.GenerateAsync(String purpose, UserManager`1 manager, TUser user)
   at n8rpg.Controllers.AccountController.Register(RegisterViewModel model) in D:\Source\n8rpg\n8rpg\n8rpg\Controllers\AccountController.cs:line 62
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I tried manually putting values in all the user properties. I can't figure out how to debug the thing to find out where my null value is... Any tips?

like image 852
wondernate Avatar asked Apr 25 '19 15:04

wondernate


2 Answers

this is GenerateAsync method of DataProtectorTokenProvider class the point that throws is showed in picture :

the point that throws is showed in picture

in my case i defined Id property in my User class :

   public class ApplicationUser : IdentityUser<long>,IFormModel,IEntity
{
    
    public long Id { get; set; }
....

also you can check this answer

like image 126
Mohammad Jafariyan Avatar answered Sep 17 '22 00:09

Mohammad Jafariyan


Most likely "Id" property of the "user" instance is null. You need to CreateUser first. When it's created successfully, you can generate email confirmation token too.

like image 25
Umut Çömlekçioğlu Avatar answered Sep 19 '22 00:09

Umut Çömlekçioğlu