首页 新闻 会员 周边 捐助

基于 IdentityServer4 的项目升级到 .NET 7 遇到问题

1
悬赏园豆:30 [已解决问题] 解决于 2022-11-20 11:45

基于 IdentityServer4 的项目升级到 .NET 7 后出现下面的异常,请问如何解决?

System.TypeInitializationException: The type initializer for 'IdentityServer4.EntityFramework.Mappers.ApiResourceMappers' threw an exception.
 ---> System.ArgumentException: GenericArguments[0], 'System.Char', on 'T MaxFloat[T](System.Collections.Generic.IEnumerable`1[T])' violates the constraint of type 'T'.
 ---> System.Security.VerificationException: Method System.Linq.Enumerable.MaxFloat: type argument 'System.Char' violates the constraint of type parameter 'T'.
   at System.RuntimeMethodHandle.GetStubIfNeeded(RuntimeMethodHandleInternal method, RuntimeType declaringType, RuntimeType[] methodInstantiation)
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   --- End of inner exception stack trace ---
   at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   at AutoMapper.TypeDetails.<>c__DisplayClass30_1.<BuildPublicNoArgExtensionMethods>b__10(MethodInfo extensionMethod)
问题补充:

是 AutoMapper 的问题,详见 https://github.com/AutoMapper/AutoMapper/issues/3988

如果在项目中专门安装最新版的 AutoMapper,错误则变成

System.TypeInitializationException: The type initializer for 'IdentityServer4.EntityFramework.Mappers.ClientMappers' threw an exception.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.MissingMethodException: Method not found: '!2 AutoMapper.IMappingExpressionBase`3.ConstructUsing(System.Linq.Expressions.Expression`1<System.Func`2<!0,!1>>)'.
   at IdentityServer4.EntityFramework.Mappers.ClientMapperProfile..ctor()

问题总结:IdentityServer4 支持的 AutoMapper 版本(10.0.0-11.0.0)不支持 .NET 7,IdentityServer4 不支持的 AutoMapper 12.0.0 支持 .NET 7。

github 上的相关 issue:https://github.com/IdentityServer/IdentityServer4/issues/5486

dudu的主页 dudu | 高人七级 | 园豆:29732
提问于:2022-11-16 16:08
< >
分享
最佳答案
0

最终通过将 IdentityServer4 升级至 .NET 7 解决了问题

dudu | 高人七级 |园豆:29732 | 2022-11-20 11:45
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册