0

Having the same issue as this post.

After upgrading to AutoMapper 4.2.1, not suddenly errors are being thrown for unmapped properties when calling: Mapper.AssertConfigurationIsValid();

For most of them, I just explicitly set the .ignore() on each of the properties, but then I came to this one, it's a lot of properties and it made me think, well this violates the whole reason to use AutoMapper.

Am I missing something?

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> AutoMapper.AutoMapperConfigurationException: 
Unmapped members were found. Review the types and members below.
Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
==========================================================================================
NopCommerceOrderHeader -> OrderHeader (Destination member list)
NopCommerceAdapter.Domain.NopCommerceOrderHeader -> OTIS.Domain.InventoryMgmt.OrderHeader (Destination member list)

Unmapped properties:
Id
FacilityId
CustomerId
StatusId
RushOrderFlag
CashDiscountFlag
PayViaCODFlag
InvoicesLateFlag
OrderedByUserId
ProjectName
CustomerPONbr
CustomerRequestedDateTime
Notes
CreatedById
CreatedOn
ModifiedById
ModifiedOn
FixedCustomerPrice
WebOrderPaymentStatusId
AssignedToUserId
FinancialsId
OrderType
WorkReleaseHeaderId
StoreFrontId
CustomerContact
Customer
Facility
OrderHeaderStatus
UserProfile
UserProfile1
PODetails
TimeDetails
OrderNotifications
UserProfile2
ShippingContainerHeaders
WorkReleaseHeader
InvoiceHeaders
CreatedByName
ModifiedByName
Community
  • 1
  • 1
crichavin
  • 4,672
  • 10
  • 50
  • 95
  • Highlighting unmapped properties is exactly what `AssertConfigurationIsValid` does. So [Ignore unmapped properties](http://stackoverflow.com/questions/954480/automapper-ignore-the-rest) or just don't call `AssertConfigurationIsValid` – stuartd Jul 22 '16 at 22:52
  • Ok, so this is by design is what you are saying? I was under the assumption that AutoMapper's main benefit was not having to map each property explicitly. That it would find matching property names from the source to the destination objects, map them, and be done. So if your source and destinations don't have the exact number of properties, you have to either explicitly ignore each one (kind of against the point of it), or comment out AssertConfigurationIsValid and remember to turn it on during testing and then comment it out again after testing and before deploying. – crichavin Jul 22 '16 at 23:05
  • Maybe a config setting to ignore unmapped or not during AssertConfigurationIsValid would be helpful? – crichavin Jul 22 '16 at 23:06
  • The whole point of `AssertConfigurationIsValid` is to highlight unmapped properties (where for example the source and destination property names are different). If you don't want it to do that, don't call it. – stuartd Jul 22 '16 at 23:10
  • Ok, I thought maybe it was doing something in addition to that. If that is it's sole purpose, than I won't call it. So it doesn't try to find any Map calls in your code like `Mapper.Map(pullListDetailViewModel); ` and then ensure you have a CreateMap for that properly configured? – crichavin Jul 22 '16 at 23:14
  • No, it doesn't walk your entire code base looking for mapping code! It just validates the defined mappings - "AutoMapper checks to make sure that every single **Destination** type member has a corresponding type member on the source type", so you can have unmapped members on the source if needs be. – stuartd Jul 22 '16 at 23:15
  • found this: https://github.com/AutoMapper/AutoMapper/wiki/Configuration-validation (see the last section). Important to note that you can change this to validate against the Source or to ignore validation all together for that one map. This is beneficial to not have to turn off AssertConfigurationIsValid all together and gives you more granular control. Also, it's purpose is more than just finding unmapped properties...it also just validates for mi-spellings, etc per Jimmy - http://stackoverflow.com/questions/22946636/automapper-assertconfigurationisvalid-call-fails-but-mapping-still-works – crichavin Jul 22 '16 at 23:25
  • 1
    That could be very useful, thanks for pointing it out. – stuartd Jul 22 '16 at 23:27

0 Answers0