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 throws - Unmapped Property Names exception

See original GitHub issue

Source/destination types

public class UserModel
    {
        public string UserName { get; set; }
        public string Email { get; set; }
        public string Password { get; set; }
        public string Phone { get; set; }
        public string PhoneVerificationCode { get; set; }
        public string EmailVerificationCode { get; set; }
        public bool? IsPhoneVerified { get; set; }
        public bool? IsEmailVerified { get; set; }
        public bool IsBlocked { get; set; }
        public bool IsDeleted { get; set; }
    }

public class User : BaseEntity
    {
        public string Name { get; set; }
        public string Email { get; set; }
        public string Password { get; set; }
        public string Phone { get; set; }
        public string Job { get; set; }
        public string PhoneVerificationCode { get; set; }
        public string EmailVerificationCode { get; set; }
        public bool? IsPhoneVerified { get; set; }
        public bool? IsEmailVerified { get; set; }
        public bool IsBlocked { get; set; }
        public bool IsDeleted { get; set; }
        public bool IsReported { get; set; }
        public string ImageUrl { get; set; }
    }

Mapping configuration

class UserProfileMapper : Profile
    {
        public UserProfileMapper()
        {
            AllowNullDestinationValues = true;

            CreateMap<UserModel, User>()
                .ForMember(Entity => Entity.Name, Model => Model.MapFrom(x => x.UserName))
                .ForMember(Entity => Entity.Id, Model => Model.Ignore())
                .ForMember(Entity => Entity.Job, Model => Model.Ignore())
                .ForMember(Entity => Entity.IsReported, Model => Model.Ignore())
                .ForMember(Entity => Entity.ImageUrl, Model => Model.Ignore())
                .ForMember(Entity => Entity.CreatedAt, Model => Model.Ignore())
                .ForMember(Entity => Entity.UpdatedAt, Model => Model.Ignore());

            CreateMap<User, UserModel>()
                .ForMember(Model => Model.UserName, opt => opt.MapFrom(Entity => Entity.Name));
        }
    }

Version: x.y.z

Version 5.0.1

Expected behavior

I expect to map from UserModel to User

Actual behavior

AutoMapper throws - Unmapped Property Names exception And in the exception, visual studio tell me the properties (Name, Id, Job, IsReported, ImageUrl, CreatedAt, UpdatedAt)

Steps to reproduce

public UserModel InsertUserModel(UserModel user)
        {
            var newUser = db.Users.Add(mapper.Map<User>(user));
            return mapper.Map<UserModel>(newUser);
        }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RadwanRadoocommented, Sep 11, 2018

I can not say how i am happy in this moment. final It works. Thanks For Helping Me @lbargaoanu

0reactions
lock[bot]commented, May 5, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AutoMapper throws Unmapped property exception despite ...
AutoMapper throws Unmapped property exception despite ignore operation is set · Remove the properties one by one to try and narrow down which...
Read more >
AutoMapper Ignore Method in C# with Examples
Note: If some of the properties are not available in the destination type, then AutoMapper will not throw any exception when doing the...
Read more >
Automapper throwing exception while mapping generic ...
In this line you are mapping a child DTO object to a Partent Logical object and reverse map. The reverse map would be...
Read more >
Auto-ignore non existing destination properties with AutoMapper
If some of the properties are not available in the destination type it will not throw an exception when doing the mapping.
Read more >
C# – AutoMapper throws Unmapped property exception ...
C# – AutoMapper throws Unmapped property exception despite ignore operation is set. asp.netasp.net-coreautomapperc++. I'm trying to map my DTO class to the ...
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