1

I'm upgrading code to use the latest version of AutoMapper in a very large solution. In several of the AutoMapper profiles there are duplicate bindings between two objects - each with different calls to ForMember(). These went unnoticed by developers before me but I think because I'm now calling .AssertConfigurationIsValid(), I'm seeing an exception that lists the duplicate mappings.

Someone else wrote this code and I don't know the business logic behind it. I'd like to resolve the issues without changing how the application works if possible, but I need to know what AutoMapper does in these cases. Best case scenario is if AutoMapper overwrites the previous mapping when it encounters another mapping between the same objects which means I can just delete all the duplicate mappings except for the last ones that appear in the profile. But if it does some kind of merging of the mappings, then I'll have more work to do.

What does AutoMapper do with duplicate mappings?

adam0101
  • 29,096
  • 21
  • 96
  • 174
  • In newer versions, it throws and there is a [setting](https://github.com/AutoMapper/AutoMapper/blob/88a7c788124c184ca570d21f4dda4da32cb17a3b/src/AutoMapper/AdvancedConfiguration.cs#L26) to get the old bevahior, merge. – Lucian Bargaoanu Oct 19 '18 at 16:51

0 Answers0