IdentityServer4 dotnet7产生异常

huangapple go评论85阅读模式
英文:

IdentityServer4 dotnet7 produce exception

问题

当使用Automaper 10.1.1、IdentityServer4和.NET 7时,IdentityServer4是IdentityServer的最新免费版本,不与更高版本的Automapper一起使用,该问题在以下链接中得到解决:问题
Automapper 10 + Identity Server 4 + .NET 7
当我访问/.well-known/openid-configuration时,我收到了以下异常信息

ArgumentException: GenericArguments[0], 'System.Char', on 'T MaxFloat[T](System.Collections.Generic.IEnumerable`1[T])' violates the constraint of type 'T'.
System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
AutoMapper.TypeDetails+<>c__DisplayClass28_1.<BuildPublicNoArgExtensionMethods>b__10(MethodInfo extensionMethod)
System.Linq.Enumerable+WhereSelectArrayIterator<TSource, TResult>.MoveNext()
System.Linq.Enumerable+ConcatIterator<TSource>.MoveNext()
System.Linq.Enumerable.SelectManyIterator<TSource, TCollection, TResult>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)+MoveNext()
System.Linq.Enumerable+WhereSelectEnumerableIterator<TSource, TResult>.MoveNext()
System.Collections.Generic.HashSet<T>.UnionWith(IEnumerable<T> other)
System.Linq.Enumerable+UnionIterator<TSource>.FillSet()
System.Linq.Enumerable+UnionIterator<TSource>.ToArray()
AutoMapper.TypeDetails.BuildPublicNoArgExtensionMethods(IEnumerable<MethodInfo> sourceExtensionMethodSearch)
AutoMapper.TypeDetails..ctor(Type type, ProfileMap config)
AutoMapper.ProfileMap.TypeDetailsFactory(Type type)
AutoMapper.Internal.LockingConcurrentDictionary<TKey, TValue>+<>c__DisplayClass2_1.<.ctor>b__1()
System.Lazy<T>.ViaFactory(LazyThreadSafetyMode mode)
System.Lazy<T>.ExecutionAndPublication(LazyHelper executionAndPublication, bool useDefaultConstructor)
System.Lazy<T>.CreateValue()
AutoMapper.Internal.LockingConcurrentDictionary<TKey, TValue>.GetOrAdd(TKey key)
AutoMapper.ProfileMap.CreateTypeDetails(Type type)
AutoMapper.TypeMapFactory.CreateTypeMap(Type sourceType, Type destinationType, ProfileMap options, bool isReverseMap)
AutoMapper.ProfileMap.BuildTypeMap(IConfigurationProvider configurationProvider, ITypeMapConfiguration config)
AutoMapper.ProfileMap.Register(IConfigurationProvider configurationProvider)
AutoMapper.MapperConfiguration.Seal()
AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression)
AutoMapper.MapperConfiguration..ctor(Action<IMapperConfigurationExpression> configure)
IdentityServer4.EntityFramework.Mappers.IdentityResourceMappers..cctor()
// 在此处放置您的源/目标类型

我尝试了所有更高版本,但由于Identity Server 4需要Automapper版本>=10且<11,所以我得到了以下异常:

System.MissingMethodException: Method not found: '!2 AutoMapper.IMappingExpressionBase`3.ConstructUsing(System.Linq.Expressions.Expression`1&lt;System.Func`2&lt;!0,!1&gt;&gt;)'.
   at IdentityServer4.EntityFramework.Mappers.ClientMapperProfile..ctor()
   at System.RuntimeType.CreateInstanceOfT()
英文:

when using Automaper 10.1.1, with identityserver4 and .net 7, identityserver4 is the last free version of IdentityServer and doesn't work with a higher version of AutoMapper where this issue is resolved in this link: Issue.
Automapper 10 + identity server 4 + dotnet 7
simply when I hit /.well-known/openid-configuration I got this exception

ArgumentException: GenericArguments[0], &#39;System.Char&#39;, on &#39;T MaxFloat[T](System.Collections.Generic.IEnumerable`1[T])&#39; violates the constraint of type &#39;T&#39;.
System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
AutoMapper.TypeDetails+&lt;&gt;c__DisplayClass28_1.&lt;BuildPublicNoArgExtensionMethods&gt;b__10(MethodInfo extensionMethod)
System.Linq.Enumerable+WhereSelectArrayIterator&lt;TSource, TResult&gt;.MoveNext()
System.Linq.Enumerable+ConcatIterator&lt;TSource&gt;.MoveNext()
System.Linq.Enumerable.SelectManyIterator&lt;TSource, TCollection, TResult&gt;(IEnumerable&lt;TSource&gt; source, Func&lt;TSource, IEnumerable&lt;TCollection&gt;&gt; collectionSelector, Func&lt;TSource, TCollection, TResult&gt; resultSelector)+MoveNext()
System.Linq.Enumerable+WhereSelectEnumerableIterator&lt;TSource, TResult&gt;.MoveNext()
System.Collections.Generic.HashSet&lt;T&gt;.UnionWith(IEnumerable&lt;T&gt; other)
System.Linq.Enumerable+UnionIterator&lt;TSource&gt;.FillSet()
System.Linq.Enumerable+UnionIterator&lt;TSource&gt;.ToArray()
AutoMapper.TypeDetails.BuildPublicNoArgExtensionMethods(IEnumerable&lt;MethodInfo&gt; sourceExtensionMethodSearch)
AutoMapper.TypeDetails..ctor(Type type, ProfileMap config)
AutoMapper.ProfileMap.TypeDetailsFactory(Type type)
AutoMapper.Internal.LockingConcurrentDictionary&lt;TKey, TValue&gt;+&lt;&gt;c__DisplayClass2_1.&lt;.ctor&gt;b__1()
System.Lazy&lt;T&gt;.ViaFactory(LazyThreadSafetyMode mode)
System.Lazy&lt;T&gt;.ExecutionAndPublication(LazyHelper executionAndPublication, bool useDefaultConstructor)
System.Lazy&lt;T&gt;.CreateValue()
AutoMapper.Internal.LockingConcurrentDictionary&lt;TKey, TValue&gt;.GetOrAdd(TKey key)
AutoMapper.ProfileMap.CreateTypeDetails(Type type)
AutoMapper.TypeMapFactory.CreateTypeMap(Type sourceType, Type destinationType, ProfileMap options, bool isReverseMap)
AutoMapper.ProfileMap.BuildTypeMap(IConfigurationProvider configurationProvider, ITypeMapConfiguration config)
AutoMapper.ProfileMap.Register(IConfigurationProvider configurationProvider)
AutoMapper.MapperConfiguration.Seal()
AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression)
AutoMapper.MapperConfiguration..ctor(Action&lt;IMapperConfigurationExpression&gt; configure)
IdentityServer4.EntityFramework.Mappers.IdentityResourceMappers..cctor()
// Put your source/destination types here

I tryed all Higher versions and I get another exception because identity server 4 requires AutoMapper version>=10 and <11, in this case I got this exception:

System.MissingMethodException: Method not found: &#39;!2 AutoMapper.IMappingExpressionBase`3.ConstructUsing(System.Linq.Expressions.Expression`1&lt;System.Func`2&lt;!0,!1&gt;&gt;)&#39;.
   at IdentityServer4.EntityFramework.Mappers.ClientMapperProfile..ctor()
   at System.RuntimeType.CreateInstanceOfT()

答案1

得分: 6

我找到了一个解决方案

  1. 只需复制/粘贴这两个项目并创建自己的库:

IdentityServer4.EntityFramework

IdentityServer4.EntityFramework.Storage

  1. 升级 Mapper 版本并修复 IdentityServer4.EntityFramework.Storage 库中的可空引用类型。
  2. 从代码中删除包并替换为您自己的库。
    IdentityServer4 dotnet7产生异常

.well-known/openid-configuration 现在对我有效。

英文:

I found a solution

  1. Just copy/paste these 2 projects and create own libraries:

IdentityServer4.EntityFramework

IdentityServer4.EntityFramework.Storage

  1. Bump Mapper version and fix Nullable reference types in IdentityServer4.EntityFramework.Storage lib.
  2. Remove packages from code and replace with your libraries.
    IdentityServer4 dotnet7产生异常

.well-known/openid-configuration now works for me.

答案2

得分: 2

我昨天也遇到了这个问题 - 花了很多时间寻找解决方案,但找不到。
我决定将 .net 降级到 6.0,然后它就正常工作了 - 尽管 IS4.EF.Storage 的要求提到支持 .net 7.0。

也许你应该看看 Duende.IdentityServer

这是由 IS4 的创作者创建的新公司。问题可能已经在那里得到解决。由于它们的相似性,从 IS4 切换到 Duende 不应该很困难。

英文:

I also saw this problem yesterday - spent a lot of time looking for a solution but couldnt.
I decided to downgrade .net to 6.0 then it worked - though, the requirements of IS4.EF.Storage mention support to .net 7.0

> Maybe you should look at Duende.IdentityServer

This is new company by creators of IS4. Probably the issue has been resolved there. Switching from IS4 to Duende shouldnt be difficult due to their similarity

答案3

得分: 1

你可以使用这个包,其中包含了更新后的AutoMapper:

此外,详细讨论请参考这里:https://github.com/IdentityServer/IdentityServer4/issues/5486

英文:

As an update from the answer by @Tapac, you can use this package which has the updated AutoMapper

Also, this is discussed in detail here: https://github.com/IdentityServer/IdentityServer4/issues/5486

答案4

得分: 1

你可以直接将Automapper的新版本安装到你的顶层项目,然后解决方案将使用它们。

英文:

You can install new version of Automapper directly to your top level projects and solution would use them.

huangapple
  • 本文由 发表于 2023年2月8日 23:57:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75388425.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定