5

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?

3
  • 1
    So if I have overriden the IdentityUser so I could add some fields to the user table. If I revert to using IdentityUser it works. So something is not working when I use my own user object. Does that make sense? Commented Apr 25, 2019 at 16:41
  • From source here github.com/aspnet/AspNetIdentity/blob/master/src/… I would say that user's Id property is null Commented May 1, 2019 at 7:21
  • @wondernate You have not provided enough details ( a minimal reproducible example). There is not much help that can be provided with the limited information here. Commented May 6, 2019 at 21:30

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.