Upgrade AutoMapper to support .NET 7
See original GitHub issueHi,
This is mainly a FYI for any other developers that are running into issues when trying out Piranha with .NET 7 preview. The precursor here is that I created a simple Piranha project from the piranha.mvc template, and then try to run it with a .NET 7 preview runtime. The following exception is thrown:
Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.TypeInitializationException: The type initializer for 'Piranha.Data.EF.Module' threw an exception.
---> System.ArgumentException: GenericArguments[0], 'Piranha.Extend.Fields.ImageField', on 'T MaxInteger[T](System.Collections.Generic.IEnumerable`1[T])' violates the constraint of type 'T'.
---> System.Security.VerificationException: Method System.Linq.Enumerable.MaxInteger: type argument 'Piranha.Extend.Fields.ImageField' 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__DisplayClass28_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.Configuration.Conventions.NameSplitMember.MapDestinationPropertyToSource(ProfileMap options, TypeDetails sourceType, Type destType, Type destMemberType, String nameToSearch, LinkedList`1 resolvers, IMemberConfiguration parent, Boolean isReverseMap)
at AutoMapper.Configuration.Conventions.MemberConfiguration.MapDestinationPropertyToSource(ProfileMap options, TypeDetails sourceType, Type destType, Type destMemberType, String nameToSearch, LinkedList`1 resolvers, Boolean isReverseMap)
at AutoMapper.ProfileMap.MapDestinationPropertyToSource(TypeDetails sourceTypeInfo, Type destType, Type destMemberType, String destMemberInfo, LinkedList`1 members, Boolean reverseNamingConventions)
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 Piranha.Data.EF.Module..cctor()
--- End of inner exception stack trace ---
at Piranha.Data.EF.Module..ctor()
at System.RuntimeType.CreateInstanceOfT()
--- End of inner exception stack trace ---
at System.RuntimeType.CreateInstanceOfT()
at System.Activator.CreateInstance[T]()
at Piranha.Runtime.AppModuleList.OnRegister[TValue](AppModule item)
at Piranha.Runtime.AppDataList`2.Register[TValue]()
at PiranhaEFExtensions.RegisterServices[T](IServiceCollection services, ServiceLifetime scope)
at PiranhaEFExtensions.AddPiranhaEF[T](IServiceCollection services, Action`1 dboptions, Int32 poolSize, ServiceLifetime scope)
at PiranhaEFExtensions.UseEF[T](PiranhaServiceBuilder serviceBuilder, Action`1 dboptions, Int32 poolSize, ServiceLifetime scope)
at Program.<>c__DisplayClass0_0.<<Main>$>b__0(PiranhaServiceBuilder options) in C:\Projects\ramn-web\src\Ramn.Web.MVC\Program.cs:line 29
at PiranhaStartupExtensions.AddPiranha(IServiceCollection services, Action`1 options, ServiceLifetime scope)
at PiranhaHostingExtensions.AddPiranha(WebApplicationBuilder builder, Action`1 options)
This is a known issue since .NET 7.0 preview.5.22258.1. Here are some relevant links:
- First issue posted on dotnet/runtime https://github.com/dotnet/runtime/issues/69119
- Automapper issue: https://github.com/AutoMapper/AutoMapper/issues/3988
- Old proposal from Automapper author to improve CoreFX API: https://github.com/dotnet/runtime/issues/28033
- Automapper pull request: https://github.com/AutoMapper/AutoMapper/pull/3999
The conclusion is that this issue is supposedly fixed in Automapper 11.0.2 which is not released yet.
I’m posting this issue + background information here in case other users happen across this problem while preparing for the upcoming .NET 7 upgrade. Feel free to close this when Automapper 11.0.2 is released and the fix is verified.
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Upgrade from AutoMapper 7.0.1 to 11.0.1 how to handle ` ...
I'm trying to migrate an existing .NET Framework 4.8 WebApi project to .NET 6.0. I have installed the latest version of AutoMapper by...
Read more >11.0 Upgrade Guide
11.0 Upgrade Guide¶. Release notes. AutoMapper now targets .Net Standard 2.1 and doesn't work on .Net Framework ...
Read more >AutoMapper documentation
AutoMapper is geared towards model projection scenarios to flatten complex object models to DTOs and other simple objects, whose design is better suited...
Read more >AutoMapper 12.0.1
What is AutoMapper? AutoMapper is a simple little library built to solve a deceptively complex problem - getting rid of code that mapped...
Read more >Getting Started with AutoMapper in ASP.NET Core
we are going to learn how to use the AutoMapper in a .NET Core application. We will look into what the AutoMapper is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Would it be possible to get this fix released as a patch version instead of waiting for all the issues for 10.30 to have been resolved? We are quite eager to start moving to .net 7 for some of our solutions
Could you clarify? The last version of Piranha that was compiled for NetStandard 2.0 was version
9.2