0

I'm currently facing an issue while trying to seed data for IdentityServer4 using Entity Framework Core with SQL Server. I followed the quickstart guide, but I'm encountering problems when seeding IdentityResources, ApiScopes, ApiResources, and Clients. Even standard IdentityResources like OpenId are causing seeding issues.

Here's the specific exception I'm encountering:

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)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at System.Linq.Enumerable.SelectManyIterator[TSource,TCollection,TResult](IEnumerable`1 source, Func`2 collectionSelector, Func`3 resultSelector)+MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
   at System.Linq.Enumerable.UnionIterator`1.FillSet()
   at System.Linq.Enumerable.UnionIterator`1.ToArray()
   at AutoMapper.TypeDetails.BuildPublicNoArgExtensionMethods(IEnumerable`1 sourceExtensionMethodSearch)
   at AutoMapper.TypeDetails..ctor(Type type, ProfileMap config)
   at AutoMapper.ProfileMap.TypeDetailsFactory(Type type)
   at AutoMapper.Internal.LockingConcurrentDictionary`2.<>c__DisplayClass2_1.<.ctor>b__1()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at AutoMapper.Internal.LockingConcurrentDictionary`2.GetOrAdd(TKey key)
   at AutoMapper.ProfileMap.CreateTypeDetails(Type type)
   at AutoMapper.TypeMapFactory.CreateTypeMap(Type sourceType, Type destinationType, ProfileMap options, Boolean isReverseMap)
   at AutoMapper.ProfileMap.BuildTypeMap(IConfigurationProvider configurationProvider, ITypeMapConfiguration config)
   at AutoMapper.ProfileMap.Register(IConfigurationProvider configurationProvider)
   at AutoMapper.MapperConfiguration.Seal()
   at AutoMapper.MapperConfiguration..ctor(MapperConfigurationExpression configurationExpression)
   at AutoMapper.MapperConfiguration..ctor(Action`1 configure)
   at IdentityServer4.EntityFramework.Mappers.IdentityResourceMappers..cctor()

I suspect there might be a constraint related to a property, but I'm uncertain about the root cause.

Could someone please provide insights into what might be causing this exception and how I can resolve it? Any help would be greatly appreciated.

As a troubleshooting step, I've tried filling out every property on an IdentityResource, but that didn't resolve the issue.

3
  • "I followed the quickstart guide" - which quickstart guide? i do curious, can you share the link? is it this one?
    – Bagus Tesa
    Commented Jun 24 at 21:25
  • Yes exactly! and the problem appears on these lines -> { foreach (var client in Config.GetClients()) { context.Clients.Add(client.ToEntity()); } context.SaveChanges(); }
    – ByteNinja
    Commented Jun 25 at 5:09
  • You have to include code when asking questions about code that fails. Commented Jun 26 at 18:11

1 Answer 1

0

for everyone that also encounters this problem I upgraded AutoMapper to version 12. I also Updated Cnblogs.Identity.Server4.EntityFramework.Storage to version 4.2.1 and this solved my problem when seeding!

Not the answer you're looking for? Browse other questions tagged or ask your own question.