question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AutoMapper 6.2.* + AutoMapper.Collection => System.ArgumentException: 'Argument types do not match'

See original GitHub issue

We 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(Stack1 typeMapsPath) at AutoMapper.TypeMap.Seal(IConfigurationProvider configurationProvider, Stack1 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
TylerCarlson1commented, Nov 22, 2017

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.

0reactions
TylerCarlson1commented, Nov 27, 2017

Someone else verified it worked. It’s released as 3.1.3 on NuGet now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Argument types do not match - Stack Overflow
i got the same error ArgumentException: Argument types do not match, but id map fine. its return exception: var test = _context.Set<Chat>() ....
Read more >
ProjectTo exception: Argument types do not match #2440
I have been unable to get ProjectTo working in even simple scenarios in a class library that targets .NET Standard 2.0.
Read more >
AutoMapper.QueryableExtensions.Project doesn't work ...
Project throws ArgumentException with message ""Argument types do not match". Here is the simple repro code: using System; using System.Collections;
Read more >
EF core exception System.ArgumentException:Argument ...
Coding example for the question EF core exception System.ArgumentException:Argument types do not match System.Linq.Expressions.Expression.
Read more >
AutoMapper Documentation
convention-based matching algorithm to match up source to destination values. AutoMapper is geared towards model.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found