AutoMapper throws - Unmapped Property Names exception
See original GitHub issueSource/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:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can not say how i am happy in this moment. final It works. Thanks For Helping Me @lbargaoanu
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.