AutoMapper 6.2.* + AutoMapper.Collection => System.ArgumentException: 'Argument types do not match'
See original GitHub issueWe just updated AutoMapper from version 6.1.1 to 6.2.0. I also tried the more recently released 6.2.1 and the issue still persists.
As soon as we did we not get System.ArgumentException: ‘Argument types do not match’ on application startup.
at System.Linq.Expressions.Expression.Condition(Expression test, Expression ifTrue, Expression ifFalse) at AutoMapper.Mappers.EquivalentExpressionAddRemoveCollectionMapper.MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap, PropertyMap propertyMap, Expression sourceExpression, Expression destExpression, Expression contextExpression) at AutoMapper.Execution.ExpressionBuilder.MapExpression(IConfigurationProvider configurationProvider, ProfileMap profileMap, TypePair typePair, Expression sourceParameter, Expression contextParameter, PropertyMap propertyMap, Expression destinationParameter) at AutoMapper.Execution.TypeMapPlanBuilder.CreatePropertyMapFunc(PropertyMap propertyMap, Expression destination) at AutoMapper.Execution.TypeMapPlanBuilder.TryPropertyMap(PropertyMap propertyMap) at AutoMapper.Execution.TypeMapPlanBuilder.CreateAssignmentFunc(Expression destinationFunc, Boolean constructorMapping) at AutoMapper.Execution.TypeMapPlanBuilder.CreateMapperLambda(Stack
1 typeMapsPath) at AutoMapper.TypeMap.Seal(IConfigurationProvider configurationProvider, Stack
1 typeMapsPath) at AutoMapper.MapperConfiguration.Seal() at AutoMapper.MapperConfiguration…ctor(MapperConfigurationExpression configurationExpression) at TestApp.Startup.ConfigureServices(IServiceCollection services) in C:\Users\natha\source\repos\TestApp\TestApp\Startup.cs:line 115
It is thrown from this code
var mapperConfiguration = new MapperConfiguration(_ =>
{
_.AddCollectionMappers();
_.AddProfile<DefaultProfile>();
});
I’ve tried looking up how to resolve this, but found nothing. I don’t understand what’s causing it. Everything worked before updating.
I made a new repo demonstrating the problem here.
The project that demonstrates the issue is a cut down version containing parts of the original application we first witnessed the issue happening. All of the internal nuget packages not available publicly have been converted to projects within the solution to be referenced.
The project TestApp should be set to be the startup project. Within TestApp.csproj you will see the nuget package reference to AutoMapper 6.2.1. Left in place the exception will be thrown on startup. If changed to 6.1.1, the application starts normally.
I feel this might be related to AutoMapper.Collection as if I remove the lines
_.AddCollectionMappers();
and lines like this from the mapping Profile
.EqualityComparison((source, target) => source.SectionId == target.SectionId)
then application starts. But without the collection equality comparisons, the mapping does not work correctly.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top GitHub Comments
Having issue with .NET Core update with AM 6.2.1 and getting it to build because of references. Once I get the build working it will be pushed to NuGet.
Someone else verified it worked. It’s released as 3.1.3 on NuGet now