Hello everyone !
The method .ToEntity() from IdentityServer4.EntityFramework.Mappers is not working anymore when upgrading AutoMapper to 8.0
From http://docs.automapper.org/en/latest/8.0-Upgrade-Guide.html
// IMappingExpression<TSource, TDestination>
// Old
IMappingExpression<TSource, TDestination> ConstructUsing(Func<TSource, TDestination> ctor);
IMappingExpression<TSource, TDestination> ConstructUsing(Func<TSource, ResolutionContext, TDestination> ctor);
IMappingExpression<TSource, TDestination> ConstructProjectionUsing(Expression<Func<TSource, TDestination>> ctorExpression);
// New
IMappingExpression<TSource, TDestination> ConstructUsing(Expression<Func<TSource, TDestination>> ctor);
IMappingExpression<TSource, TDestination> ConstructUsing(Func<TSource, ResolutionContext, TDestination> ctor);
// IMappingExpression
// Old
IMappingExpression ConstructUsing(Func<object, object> ctor);
IMappingExpression ConstructUsing(Func<object, ResolutionContext, object> ctor);
IMappingExpression ConstructProjectionUsing(LambdaExpression ctorExpression);
// New
IMappingExpression ConstructUsing(Expression<Func<object, object>> ctor);
IMappingExpression ConstructUsing(Func<object, ResolutionContext, object> ctor);
Existing ConstructUsing usages
The change from Func to Expression may break some existing usages. Namely:ConstructUsing using lambda statements, method groups, or delegates
- Dual configuration of ConstructProjectionUsing and ConstructUsing
- For the first case, you may either:
Convert to a lambda expression
- Move to the Func-based overload
- The Func-based overload accepts more parameters, so you may have to add the parameters to your delegates.
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'IdentityServer4.EntityFramework.Mappers.ClientMappers' threw an exception.
Source=IdentityServer4.EntityFramework.Storage
StackTrace:
at IdentityServer4.EntityFramework.Mappers.ClientMappers.ToEntity(Client model)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Inner Exception 1:
TargetInvocationException: Exception has been thrown by the target of an invocation.
Inner Exception 2:
MissingMethodException: Method not found: 'AutoMapper.IMappingExpression`2<!0,!1> AutoMapper.IMappingExpression`2.ConstructUsing(System.Func`2<!0,!1>)'.
Confirm. After reverting back to AutoMapper v7.0.1 IdentityServer working again.
I had problems even with /.well-known/openid-configuration
Sure, 8.x could be breaking changes. Why are you updating to it?
blind love to up to date software 8-/
Still, IdSrv is brilliant!
@brockallen
Sounds like it's bad practices to be up-to-date =D
Developers could start new project from scratch, where latest AutoMapper will be installed, and they will face issue.
Well, feel free to figure out the issue and submit a PR then.
I updated the store project to 8.0 of automapper and everything is working without any code changes. Not sure why tyou got a runtime exception, but I have the EF host same working just fine. I tracked the change here: #2852. Have a test with the myget feed to check, please.
Updated to 2.3.1 and still the same issue :
Message=The type initializer for 'IdentityServer4.EntityFramework.Mappers.ClientMappers' threw an exception.
Source=IdentityServer4.EntityFramework.Storage
StackTrace:
at IdentityServer4.EntityFramework.Mappers.ClientMappers.ToEntity(Client model)
...
Inner Exception 2:
MissingMethodException: Method not found: 'AutoMapper.IMappingExpression`2<!0,!1> AutoMapper.IMappingExpression`2.ConstructUsing(System.Func`2<!0,!1>)'.
This is still a problem. Also facing same with AutoMapper 8.0.0:
at IdentityServer4.EntityFramework.Mappers.ClientMappers.ToEntity(Client model) in C:\local\identity\server4\EntityFramework.Storage\src\Mappers\ClientMappers.cs:line 39
TypeInitializationException: The type initializer for 'IdentityServer4.EntityFramework.Mappers.ClientMappers' threw an exception.
IdentityServer4.EntityFramework.Mappers.ClientMappers.ToEntity(Client model) in ClientMappers.cs, line 39
Strange - I had the same problem. Now I tried to update to v2.3.2 and everything works as expected.
This is still a problem
Now I tried to update to v2.3.2 and everything works as expected.
If you updated the .Storage nuget it would work. Since most people won't know to do that, we updated the EF nuget to pull in the latest patch of .Storage.
Any solution to this problem?
I have "IdentityServer4.EntityFramework" v2.1.1 installed with Automapper 8.0.0 inside it.
Even the lowest version of ID4.EF has AutoMapper v8.0.0
I have tried with every version of ID4.EF, doesn't work
We updated to AutoMapper 8 starting 2.3.2
with automapper 8.1 there is the same problem.
with automapper 8.1 there is the same problem.
I can confirm that the problem remains with AutoMapper 8.1.0, however is indeed working with AutoMapper 8.0.0:
System.TypeInitializationException : The type initializer for 'IdentityServer4.EntityFramework.Mappers.IdentityResourceMappers' threw an exception.
----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.MissingMethodException : Method not found: 'AutoMapper.IMappingExpression`2<!0,!1> AutoMapper.IMappingExpression`2.ConstructUsing(System.Linq.Expressions.Expression`1<System.Func`2<!0,!1>>)'.
at IdentityServer4.EntityFramework.Mappers.IdentityResourceMappers.ToEntity(IdentityResource model)
2.4.0 does still have some issues with Automapper 8.0
Unhandled Exception: System.TypeLoadException: Could not load type 'IdentityServer4.EntityFramework.Interfaces.IConfigurationDbContext' from assembly 'IdentityServer4.EntityFramework, Version=2.4.0.0, Culture=neutral, PublicKeyToken=d651e08d0f0fa14b'.
@EricHerlitz, nothing in your stack trace suggests your issue is related to Automapper. I have verified that Automapper 8.0.0 is working fine for me with IdentityServer 2.4.0.
IdentityServer 2.4.0 and AutoMapper 8.1 still breaking changes,but the 8.0 is well,<( ̄▽ ̄)/
I did not have an issue until upgrading from automapper from 8.0.0 to 8.1. 0. I am using IdentityServer4 2.4.0. Perhaps the same issue?
This is happening to me as well. I have a very basic setup using IS4/IS4.Asp/IS4.EF. And Microsoft.AspNetCore.App 2.2.4. To the best of my knowledge, nothing else is referencing AutoMapper except IS4.
My code uses the following and this is where it is failing:
var clientEntity = client.ToEntity();
Inner Exception 2:
MissingMethodException: Method not found: 'AutoMapper.IMappingExpression2<!0,!1> AutoMapper.IMappingExpression2.ConstructUsing(System.Linq.Expressions.Expression1<System.Func2>)'.
SEE: http://docs.automapper.org/en/stable/8.0-Upgrade-Guide.html
Yes, automapper 8.1 broken semantic versioning. IS 2.4 references 8.0, so please don't update to automapper 8.1. When we release 2.5, we will include the update to automapper 8.1.
Yes, I see the problem now. One of my in-house is referencing 8.1. Silly me. Thanks!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
blind love to up to date software 8-/
Still, IdSrv is brilliant!