1

I'm trying to create a record in db but I take this error at below.

its image of error page buy may not work

This is the error

 ArgumentNullException: Value cannot be null.
 Parameter name: key
System.Collections.Generic.Dictionary<TKey, TValue>.FindEntry(TKey key)
Microsoft.AspNetCore.Http.Internal.RequestCookieCollection.ContainsKey(string key)
Abp.AspNetCore.Mvc.Antiforgery.AbpAutoValidateAntiforgeryTokenAuthorizationFilter.ShouldValidate(AuthorizationFilterContext context) in AbpAutoValidateAntiforgeryTokenAuthorizationFilter.cs
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ValidateAntiforgeryTokenAuthorizationFilter.OnAuthorizationAsync(AuthorizationFilterContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

This is my controller:

  public IActionResult Index()
    {
        return View();
    }
    [HttpPost]
    public  IActionResult Index(CreateUserInput input)
    {
        if (HttpContext.Request.Cookies.ContainsKey(".AspNetCore.Antiforgery."))
        {
            _userAppService.Create(input);
        }

        return RedirectToAction("Index","Home");
    }

this is my html page:

  @model DutyV2.Users.DTO.CreateUserInput
@{
    ViewData["Title"] = "Index";
}

<h2>Index</h2>
<form asp-action="Index" method="post">
    <div class="input-group">
        <label class="control-label" asp-for="Name"></label>
        <input asp-for="Name" class="form-control" type="text" />
    </div>
    <div class="input-group">
        <label class="control-label" asp-for="Email"></label>
        <input asp-for="Email" class="form-control" type="email" />
    </div>
    <input type="submit" value="Create"/>
</form>
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
Ensar Eray
  • 66
  • 1
  • 7
  • put break point and check in the controller what values you are getting in that – Just code Dec 30 '18 at 10:22
  • @Justcode break point is not working. I guess it's not reaching to controller. – Ensar Eray Dec 30 '18 at 10:25
  • If `AbpAutoValidateAntiforgeryTokenAuthorizationFilter` is a class accessible to you I would suggest putting a breakpoint on the `ShouldValidate(context)` method. From the stack trace you provided I can see that inside that method a call for `RequestCookieCollection.ContainsKey(key)` is made with passed null key argument. – Prolog Dec 30 '18 at 13:11

1 Answers1

1

Update your ABP version to v4.0.1 or above.

It is due to ContainsKey getting called with null if cookie authentication is not used.

The bug occurred in AbpAutoValidateAntiforgeryTokenAuthorizationFilter and AbpValidateAntiforgeryTokenAuthorizationFilter.

The relevant pull request: https://github.com/aspnetboilerplate/aspnetboilerplate/pull/3986

aaron
  • 39,695
  • 6
  • 46
  • 102
  • 1
    Thanks, when I add Authentication problem is solved. Maybe it's not a good solution but for now its ideal. – Ensar Eray Dec 30 '18 at 17:11