Identityserver4的自动映射器问题-MissingMethodException:找不到方法:'!! 0 AutoMapper.IMapper.Map(System.Object)' [英] Automapper issue with identityserver4 - MissingMethodException: Method not found: '!!0 AutoMapper.IMapper.Map(System.Object)'

查看:477
本文介绍了Identityserver4的自动映射器问题-MissingMethodException:找不到方法:'!! 0 AutoMapper.IMapper.Map(System.Object)'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是IdentityServer 4的最新版本

问题/重现问题的步骤

  • 创建一个新的blazor webassembly应用
  • 我搭建了所有的身份文件并对其进行了自定义
  • 自定义ApiAuthorizationDbContext 用于出色的webassembly
  • 安装 Automapper v10 AutoMapper.Extensions.Microsoft.DependencyIn v8.0.1

当我运行项目时,浏览器中出现500错误:

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_mp =& code_tall_method = samp;&n = code_challenge_meth ==& code_challenge_meth ==&&nb; code_challenge& p; mp_n = 500

以及在自托管控制台中:

 暴击:IdentityServer4.Hosting.IdentityServerMiddleware [0]未处理的异常:找不到方法:'!! 0 AutoMapper.IMapper.Map(System.Object)'.System.MissingMethodException:找不到方法:'!! 0 AutoMapper.IMapper.Map(System.Object)'.在IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant模型)在IdentityServer4.EntityFramework.Stores.PersistedGrantStore.StoreAsync(PersistedGrant令牌)处在IdentityServer4.Stores.DefaultGrantStore`1.StoreItemAsync(String key,T item,String clientId,String subjectId,创建的DateTime,Nullable`1到期)在IdentityServer4.Stores.DefaultGrantStore`1.CreateItemAsync(T item,字符串clientId,字符串subjectId,创建的DateTime,Int32生存期)在IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest请求)处在IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest请求)处在IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection参数,ClaimsPrincipal用户,ConsentResponse同意)处在IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext上下文)处在IdentityServer4.Hosting.IdentityServerMiddleware.Invoke处(HttpContext上下文,IEndpointRouter路由器,IUserSession会话,IEventService事件)失败:Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware [1]执行请求时发生未处理的异常.System.MissingMethodException:找不到方法:'!! 0 AutoMapper.IMapper.Map(System.Object)'.在IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant模型)在IdentityServer4.EntityFramework.Stores.PersistedGrantStore.StoreAsync(PersistedGrant令牌)处在IdentityServer4.Stores.DefaultGrantStore`1.StoreItemAsync(String key,T item,String clientId,String subjectId,创建的DateTime,Nullable`1到期)在IdentityServer4.Stores.DefaultGrantStore`1.CreateItemAsync(T item,字符串clientId,字符串subjectId,创建的DateTime,Int32生存期)在IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest请求)处在IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest请求)处在IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection参数,ClaimsPrincipal用户,ConsentResponse同意)处在IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext上下文)处在IdentityServer4.Hosting.IdentityServerMiddleware.Invoke处(HttpContext上下文,IEndpointRouter路由器,IUserSession会话,IEventService事件)在IdentityServer4.Hosting.IdentityServerMiddleware.Invoke处(HttpContext上下文,IEndpointRouter路由器,IUserSession会话,IEventService事件)在IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke处(HttpContext上下文,IAuthenticationSchemeProvider方案)在Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext上下文)在IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext上下文)在Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext上下文)在Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext上下文)在Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext上下文)在Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)在Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)在Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext上下文) 

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& promp

 在处理请求时发生未处理的异常.MissingMethodException:找不到方法:'!! 0 AutoMapper.IMapper.Map(System.Object)'.IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant模型) 

堆栈:

  MissingMethodException:找不到方法:'!! 0 AutoMapper.IMapper.Map(System.Object)'.IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant模型)IdentityServer4.EntityFramework.Stores.PersistedGrantStore.StoreAsync(PersistedGrant令牌)IdentityServer4.Stores.DefaultGrantStore< T> .StoreItemAsync(字符串键,T项目,字符串clientId,字符串subjectId,创建的DateTime,Nullable< DateTime>到期)IdentityServer4.Stores.DefaultGrantStore< T> .CreateItemAsync(T项目,字符串clientId,字符串subjectId,创建的DateTime,int生命周期)IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest请求)IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest请求)IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection参数,ClaimsPrincipal用户,ConsentResponse同意)IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext上下文)IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext上下文,IEndpointRouter路由器,IUserSession会话,IEventService事件)IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext上下文,IEndpointRouter路由器,IUserSession会话,IEventService事件)IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext上下文,IAuthenticationSchemeProvider方案)Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext上下文)IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext上下文)Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext上下文)Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext上下文)Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext上下文)Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext上下文) 

显示原始异常详细信息

  System.MissingMethodException:找不到方法:'!! 0 AutoMapper.IMapper.Map(System.Object)'.在IdentityServer4.EntityFramework.Mappers.PersistedGrantMappers.ToEntity(PersistedGrant模型)在IdentityServer4.EntityFramework.Stores.PersistedGrantStore.StoreAsync(PersistedGrant令牌)处在IdentityServer4.Stores.DefaultGrantStore`1.StoreItemAsync(String key,T item,String clientId,String subjectId,创建的DateTime,Nullable`1到期)在IdentityServer4.Stores.DefaultGrantStore`1.CreateItemAsync(T item,字符串clientId,字符串subjectId,创建的DateTime,Int32生存期)在IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateCodeFlowResponseAsync(ValidatedAuthorizeRequest请求)处在IdentityServer4.ResponseHandling.AuthorizeResponseGenerator.CreateResponseAsync(ValidatedAuthorizeRequest请求)处在IdentityServer4.Endpoints.AuthorizeEndpointBase.ProcessAuthorizeRequestAsync(NameValueCollection参数,ClaimsPrincipal用户,ConsentResponse同意)处在IdentityServer4.Endpoints.AuthorizeEndpoint.ProcessAsync(HttpContext上下文)处在IdentityServer4.Hosting.IdentityServerMiddleware.Invoke处(HttpContext上下文,IEndpointRouter路由器,IUserSession会话,IEventService事件)在IdentityServer4.Hosting.IdentityServerMiddleware.Invoke处(HttpContext上下文,IEndpointRouter路由器,IUserSession会话,IEventService事件)在IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke处(HttpContext上下文,IAuthenticationSchemeProvider方案)在Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext上下文)在IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext上下文)在Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext上下文)在Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext上下文)在Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext上下文)在Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)在Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)在Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext上下文) 

解决方案

请勿后退,请勿降级,升级

似乎AutoMapper 10.0.0 有一个错误,解决该问题的方法是将AutoMapper升级到 10.1.1 版本.

此版本是非常新的版本,已在此答案日期前4天发布.

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)

解决方案

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.

这篇关于Identityserver4的自动映射器问题-MissingMethodException:找不到方法:'!! 0 AutoMapper.IMapper.Map(System.Object)'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆