AutoMapper / AutoMapper.Collection

AutoMapper support for updating existing collections by equivalency
MIT License
245 stars 59 forks source link

Stackoverflow on upgrade of AutoMapper.Extensions.Microsoft.DependencyInjection #153

Closed penfold closed 4 years ago

penfold commented 4 years ago

TLDR See whole chain of comments. It looks to be caused by AutoMapper.Extensions.Microsoft.DependencyInjection.

I'm getting a SO in Visual Studio when my WebApp starts up. I have extensive usage of Automapper, but I get nothing other that a SO. The call stack is:

System.Private.CoreLib.dll!System.RuntimeTypeHandle.GetGenericTypeDefinition(System.RuntimeType type)   Unknown
System.Private.CoreLib.dll!System.RuntimeType.GetGenericTypeDefinition()    Unknown

AutoMapper.Collection.dll!AutoMapper.Collection.TypeHelper.GetElementTypes(System.Type enumerableType, System.Collections.IEnumerable enumerable, AutoMapper.Collection.ElemntTypeFlags flags) Unknown AutoMapper.Collection.dll!AutoMapper.Collection.TypeHelper.GetElementType(System.Type enumerableType) Unknown AutoMapper.Collection.dll!AutoMapper.Mappers.EquivalentExpressionAddRemoveCollectionMapper.MapExpression(AutoMapper.IConfigurationProvider configurationProvider, AutoMapper.ProfileMap profileMap, AutoMapper.IMemberMap memberMap, System.Linq.Expressions.Expression sourceExpression, System.Linq.Expressions.Expression destExpression, System.Linq.Expressions.Expression contextExpression) Unknown AutoMapper.Collection.dll!AutoMapper.Mappers.EquivalentExpressionAddRemoveCollectionMapper.MapExpression(AutoMapper.IConfigurationProvider configurationProvider, AutoMapper.ProfileMap profileMap, AutoMapper.IMemberMap memberMap, System.Linq.Expressions.Expression sourceExpression, System.Linq.Expressions.Expression destExpression, System.Linq.Expressions.Expression contextExpression) Unknown . . . AutoMapper.Collection.dll!AutoMapper.Mappers.EquivalentExpressionAddRemoveCollectionMapper.MapExpression(AutoMapper.IConfigurationProvider configurationProvider, AutoMapper.ProfileMap profileMap, AutoMapper.IMemberMap memberMap, System.Linq.Expressions.Expression sourceExpression, System.Linq.Expressions.Expression destExpression, System.Linq.Expressions.Expression contextExpression) Unknown

Then SO.

Are you able to give me an idea of how I could start to debug this? (There's not much to go on.)

Thanks, Paul

penfold commented 4 years ago

When I comment out AM.Coll, the SO does not occur.

services.AddAutoMapper(configurationExpression => { //configurationExpression.AddCollectionMappers(); }, typeof(MapperFactoryExtensions).Assembly);

penfold commented 4 years ago

Upgrading from AM 9.0.0 to 10.1.1 and AM.Coll 6.0.0 to 7.0.0. (And .net core 3.1 to .net 5)

penfold commented 4 years ago

Is it possible have some exception handling in that stack to get feedback on which types are causing the issue?

penfold commented 4 years ago

I've grabbed all of the source code to help debug. It seems to be stumbling (in a recursive way) when calling EquivalentExpressionAddRemoveCollectionMapper.MapExpression(...) for

.ForMember(d => d.Errors, o => o.MapFrom((s, d) => s.Errors?.Split(';')));

This is string[] to IList\<string> .

penfold commented 4 years ago

I've tested my .net core 3.1 branch with the latest versions of AM and AM.Coll. This looks to be working correctly.

I then updated AutoMapper.Extensions.Microsoft.DependencyInjection and the SO is now seen.

TylerCarlson1 commented 4 years ago

Seems very similar to #151. Preserve References is not getting used and goes into SO loop.

You can try updating to 7.0.1-ci-00105 from nuget feed AM-prerelease and see if that fixes your problem

gokhanabatay commented 4 years ago

Same issue with .net 5.0 AutoMapper 10.1.1, AutoMapper.Collection 7.0.0, AutoMapper.Extensions.Microsoft.DependencyInjection 8.1.0

esabah commented 4 years ago

I am getting error with .net 5.0 , AutoMapper 10.1.1, AutoMapper.Collection 7.0.0, AutoMapper.Extensions.Microsoft.DependencyInjection 8.1.0.

I tried AutoMapperCollection 7.0.1-ci-00105 and worked without errors. When do you plan to release this fix? Thanks.

TylerCarlson1 commented 4 years ago

When I fix the deployment pipeline to nuget which has changed to GitHub Actions from AppVoyer

TylerCarlson1 commented 4 years ago

Got it pushed fix is in 7.0.1

rcdailey commented 1 year ago

I'd just like to point out that I'm getting this exact same issue. I'm running AutoMapper v12.0.1 and AutoMapper.Collection v9.0.0.