英文:
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<System.Func`2<!0,!1>>)'.
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], '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
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: '!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()
答案1
得分: 6
我找到了一个解决方案
- 只需复制/粘贴这两个项目并创建自己的库:
IdentityServer4.EntityFramework
IdentityServer4.EntityFramework.Storage
.well-known/openid-configuration 现在对我有效。
英文:
I found a solution
- Just copy/paste these 2 projects and create own libraries:
IdentityServer4.EntityFramework
IdentityServer4.EntityFramework.Storage
- Bump Mapper version and fix Nullable reference types in IdentityServer4.EntityFramework.Storage lib.
- Remove packages from code and replace with your libraries.
.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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论