a blog for those who code

Wednesday 12 June 2019

How to Fix AutoMapper Configuration Exception: Unmapped members were found

In this post we will go through how to fix AutoMapper.AutoMapperConfigurationException:
Unmapped members were found in ASP.NET Boilerplate. I got this error when I was using MapToEntity which is used to update the entity.

The full error states that:

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
For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters
AutoMapper created this type map for you, but your types cannot be mapped using the current configuration.
PostDto -> Post (Destination member list)
LetsDisc.Posts.Dto.PostDto -> LetsDisc.PostDetails.Post (Destination member list)

Unmapped properties:

This error was happening even though I have used [AutoMapFrom(typeof(Post))] in PostDto. But this mapping was only one way that is Post to PostDto. To do two way mapping I have to change [AutoMapFrom(typeof(Post))] to [AutoMap(typeof(Post))] for my Data Transfer Objects as shown below :

namespace LetsDisc.Posts.Dto
    public class PostDto : FullAuditedEntityDto

No comments:

Post a Comment