title: Automapper issue with identityserver4 - MissingMethodException: Method not found: '!!0 AutoMapper.IMapper.Map(System.Object)'
body: <p>I using last version of IdentityServer 4</p>
  <h3>Issue / Steps to reproduce the problem</h3>
  <ul>
  <li>Creating a new blazor webassembly app</li>
  <li>I scaffolded all the Identities files and customized</li>
  <li>and <a href="https://stackoverflow.com/questions/58208894/aspnet-core-identity-custom-apiauthorizationdbcontext">custom ApiAuthorizationDbContext</a> for blazor webassembly</li>
  <li>Install <code>Automapper v10</code> and <code>AutoMapper.Extensions.Microsoft.DependencyIn v8.0.1</code></li>
  </ul>
  <p>when I run project, in-browser give me 500 error :</p>
  <p><code>AuthenticationService.js:44 GET https://localhost:5001/connect/authorize?client_id=Web.Client&amp;redirect_uri=https%3A%2F%2Flocalhost%3A5001%2Fauthentication%2Flogin-callback&amp;response_type=code&amp;scope=Web.ServerAPI%20openid%20profile&amp;state=4b9b0120a48442a786b5bc8260c52f65&amp;code_challenge=ViBkoIwumlfy_kg_y0bAh9uFsEByt2aKDOVUSREfARE&amp;code_challenge_method=S256&amp;prompt=none&amp;response_mode=query 500</code></p>
  <p>and in self-host console:</p>
  <pre><code>crit: IdentityServer4.Hosting.IdentityServerMiddleware[0]
        Unhandled exception: Method not found: '!!0 AutoMapper.IMapper.Map(System.Object)'.
  System.MissingMethodException: Method not found: '!!0 AutoMapper.IMapper.Map(System.Object)'.
     at IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant model)
     at IdentityServer4.EntityFramework.Stores.PersistedGrantStore.StoreAsync(PersistedGrant token)
     at IdentityServer4.Stores.DefaultGrantStore`1.StoreItemAsync(String key, T item, String clientId, String subjectId, DateTime created, Nullable`1 expiration)
     at IdentityServer4.Stores.DefaultGrantStore`1.CreateItemAsync(T item, String clientId, String subjectId, DateTime created, Int32 lifetime)
     at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest request)
     at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest request)
     at IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection parameters, ClaimsPrincipal user, ConsentResponse consent)
     at IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext context)
     at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
  fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
        An unhandled exception has occurred while executing the request.
  System.MissingMethodException: Method not found: '!!0 AutoMapper.IMapper.Map(System.Object)'.
     at IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant model)
     at IdentityServer4.EntityFramework.Stores.PersistedGrantStore.StoreAsync(PersistedGrant token)
     at IdentityServer4.Stores.DefaultGrantStore`1.StoreItemAsync(String key, T item, String clientId, String subjectId, DateTime created, Nullable`1 expiration)
     at IdentityServer4.Stores.DefaultGrantStore`1.CreateItemAsync(T item, String clientId, String subjectId, DateTime created, Int32 lifetime)
     at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest request)
     at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest request)
     at IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection parameters, ClaimsPrincipal user, ConsentResponse consent)
     at IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext context)
     at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
     at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
     at IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
     at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
     at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.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)
  </code></pre>
  <p>and in <code>https://localhost:5001/connect/authorize?client_id=Web.Client&amp;redirect_uri=https%3A%2F%2Flocalhost%3A5001%2Fauthentication%2Flogin-callback&amp;response_type=code&amp;scope=Web.ServerAPI%20openid%20profile&amp;state=4b9b0120a48442a786b5bc8260c52f65&amp;code_challenge=ViBkoIwumlfy_kg_y0bAh9uFsEByt2aKDOVUSREfARE&amp;code_challenge_method=S256&amp;prompt=none&amp;response_mode=query</code> file:</p>
  <pre><code>An unhandled exception occurred while processing the request.
  MissingMethodException: Method not found: '!!0 AutoMapper.IMapper.Map(System.Object)'.
  IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant model)
  </code></pre>
  <p>Stack:</p>
  <pre><code>MissingMethodException: Method not found: '!!0 AutoMapper.IMapper.Map(System.Object)'.
  
  IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant model)
  IdentityServer4.EntityFramework.Stores.PersistedGrantStore.StoreAsync(PersistedGrant token)
  IdentityServer4.Stores.DefaultGrantStore&lt;T&gt;.StoreItemAsync(string key, T item, string clientId, string subjectId, DateTime created, Nullable&lt;DateTime&gt; expiration)
  IdentityServer4.Stores.DefaultGrantStore&lt;T&gt;.CreateItemAsync(T item, string clientId, string subjectId, DateTime created, int lifetime)
  IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest request)
  IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest request)
  IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection parameters, ClaimsPrincipal user, ConsentResponse consent)
  IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext context)
  IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
  IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
  IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
  Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
  IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
  Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
  Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.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)
  </code></pre>
  <p>Show raw exception details</p>
  <pre><code>System.MissingMethodException: Method not found: '!!0 AutoMapper.IMapper.Map(System.Object)'.
     at IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant model)
     at IdentityServer4.EntityFramework.Stores.PersistedGrantStore.StoreAsync(PersistedGrant token)
     at IdentityServer4.Stores.DefaultGrantStore`1.StoreItemAsync(String key, T item, String clientId, String subjectId, DateTime created, Nullable`1 expiration)
     at IdentityServer4.Stores.DefaultGrantStore`1.CreateItemAsync(T item, String clientId, String subjectId, DateTime created, Int32 lifetime)
     at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest request)
     at IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest request)
     at IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection parameters, ClaimsPrincipal user, ConsentResponse consent)
     at IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext context)
     at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
     at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
     at IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
     at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
     at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.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)
  </code></pre>