IdentityServer4 dotnet7 产生异常

问题描述 投票:0回答:3

当使用 Automaper 10.1.1、identityserver4 和 .net 7 时,identityserver4 是 IdentityServer 的最后一个免费版本,不能与更高版本的 AutoMapper 一起使用,此问题已在此链接中解决:Issue。 Automapper 10 + 身份服务器 4 + dotnet 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()
// Put your source/destination types here

我尝试了所有更高版本,但出现另一个异常,因为身份服务器 4 需要 AutoMapper 版本>=10 且 <11, in this case I got this exception:

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()
   at System.RuntimeType.CreateInstanceOfT()
c# migration automapper identityserver4 .net-7.0
3个回答
6
投票

我找到了解决办法

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

IdentityServer4.EntityFramework

IdentityServer4.EntityFramework.Storage

  1. Bump Mapper 版本并修复 IdentityServer4.EntityFramework.Storage lib 中的 Nullable 引用类型。
  2. 从代码中删除包并替换为您的库。

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


2
投票

我昨天也看到了这个问题 - 花了很多时间寻找解决方案但找不到。

I decided to downgrade .net to 6.0
然后它就起作用了 - 不过,IS4.EF.Storage 的要求提到了对 .net 7.0 的支持

也许你应该看看 Duende.IdentityServer

这是 IS4 创作者创建的新公司。也许问题已经解决了。从 IS4 切换到 Duende 应该不会很困难,因为它们很相似


0
投票

作为 @Tapac 答案的更新,您可以使用这个包含更新的 AutoMapper 的软件包

此外,此处详细讨论:https://github.com/IdentityServer/IdentityServer4/issues/5486

© www.soinside.com 2019 - 2024. All rights reserved.