13
votes

I using last version of IdentityServer 4

Issue / Steps to reproduce the problem

  • Creating a new blazor webassembly app
  • I scaffolded all the Identities files and customized
  • and custom ApiAuthorizationDbContext for blazor webassembly
  • Install Automapper v10 and AutoMapper.Extensions.Microsoft.DependencyIn v8.0.1

when I run project, in-browser give me 500 error :

AuthenticationService.js:44 GET https://localhost:5001/connect/authorize?client_id=Web.Client&redirect_uri=https%3A%2F%2Flocalhost%3A5001%2Fauthentication%2Flogin-callback&response_type=code&scope=Web.ServerAPI%20openid%20profile&state=4b9b0120a48442a786b5bc8260c52f65&code_challenge=ViBkoIwumlfy_kg_y0bAh9uFsEByt2aKDOVUSREfARE&code_challenge_method=S256&prompt=none&response_mode=query 500

and in self-host console:

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)

and in https://localhost:5001/connect/authorize?client_id=Web.Client&redirect_uri=https%3A%2F%2Flocalhost%3A5001%2Fauthentication%2Flogin-callback&response_type=code&scope=Web.ServerAPI%20openid%20profile&state=4b9b0120a48442a786b5bc8260c52f65&code_challenge=ViBkoIwumlfy_kg_y0bAh9uFsEByt2aKDOVUSREfARE&code_challenge_method=S256&prompt=none&response_mode=query file:

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)

Stack:

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<T>.StoreItemAsync(string key, T item, string clientId, string subjectId, DateTime created, Nullable<DateTime> expiration)
IdentityServer4.Stores.DefaultGrantStore<T>.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)

Show raw exception details

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)
4
You need an older AM. Or a newer Identity Server. See nuget.org/packages/IdentityServer4.EntityFramework.Storage.Lucian Bargaoanu
@LucianBargaoanu another error System.TypeLoadException: 'Method 'GetAllAsync' in type 'IdentityServer4.Stores.InMemoryPersistedGrantStore' from assembly 'IdentityServer4, Version=3.0.0.0, Culture=neutral, PublicKeyToken=f294d0afe402bb2b' does not have an implementation.'sda2584541
You seem to have version mismatches between your nuget references. Start from scratch with a working sample, or build yourself a simple test project.Lucian Bargaoanu
I using Blazor Webassembly Individual user account with default Authenticationsda2584541

4 Answers

8
votes

Do not move backward, Do not downgrade, Upgrade

It seems that the AutoMapper 10.0.0 has a bug, the solution to that problem was to upgrade AutoMapper to 10.1.1 version.

This version is very new, it released 4 days before the date of this answer.

5
votes

Had the same issue after adding AutoMapper to another project. I was using the same versions. Identity 3.1.8

Automapper v10 and AutoMapper.Extensions.Microsoft.DependencyIn v8.0.1

I found the best solution for me is to rollback the Automapper version to 9 and the DI respectively.

3
votes

I don't think it's related to identityserver but more the fact that there was 2 differents version of AutoMapper used.

I just had this issue in a solution with a few projects in it and yesterday I updated AutoMapper in one of them leaving another project with the old version.

Result, the application was broken.

I just updated the other project and it's now working fine.

1
votes

Was buged by this lately. Turns out it was an AutoMapper missmatch between 2 consumers.

ProjA has dependency on AutoMapper version X and ProjB version Y. ProjB Has dependency on AutoMapper version x.

When ProjA updateted its AutoMapper version ( from 9 to 10 for us ), without also updating the matched AutoMapper, to the same versionas the nuget coming from ProjB, ProjB was unable to operate, since the fetched mapper v10 had breaking changes with the v9 dll.

If you project references AutoMapper be carefull of braking changes between version, when using assembly binding to redirect dlls on published projects