1

I'm working on a project with asp.net core and Identity, I am trying to create a mapping configuration between IdentityUser subclasse and its correspondant DTO using Automapper I have done similar configuration with other classes and it works fine, but with IdentityUser subclass it behaves differently :

Here is my IdentityUser subclasse :

public partial class Collaborateur : IdentityUser
{
    public Collaborateur() : base()
    {
        this.Activites = new HashSet<ActiviteCollaborateur>();
        this.ActeursAvantVente = new HashSet<ActeurAvv>();
    }

    public string Nom { get; set; }
    public string Prenom { get; set; }
    public string Telephone { get; set; }
    public Nullable<long> Matricule { get; set; }
    public string Structure { get; set; }
    public string Login { get; set; }
    public RoleEnum Role { get; set; }
    public virtual ICollection<ActiviteCollaborateur> Activites { get; set; }
    public virtual ICollection<ActeurAvv> ActeursAvantVente { get; set; }
    public virtual Agence Agence { get; set; }
    public DateTime CreatedAt { get; set; }
    public DateTime LastModified { get; set; }
}

Its corresponding DTO :

public class CollaborateurDTO : BaseDTO
{
    public string Nom { get; set; }
    public string Prenom { get; set; }
    public string Telephone { get; set; }
    public Nullable<long> Matricule { get; set; }
    public string Structure { get; set; }
    public string Login { get; set; }
    public RoleEnum Role { get; set; }
}

CollaborateurProfile config class :

public class CollaborateurProfile : Profile
{
    CollaborateurProfile()
    {
        CreateMap<Collaborateur, CollaborateurDTO>().ReverseMap();
        CreateMap<Collaborateur, Collaborateur>()
            .ForMember(x => x.Id, opt => opt.Ignore())
            .ForMember(x => x.CreatedAt, opt => opt.Ignore())
            .ForMember(x => x.LastModified, opts => opts.MapFrom(src => DateTime.UtcNow));
    }
}

and Startup.cs :

services.AddAutoMapper();

it stops at this line with

MissingMethodException was unhandled by user code An exception of type 'System.MissingMethodException' occurred in System.Private.CoreLib.ni.dll but was not handled in user code

  • Can you try deleting bin and obj folders from your project, recompiling the project, and running again? See http://stackoverflow.com/questions/8058832/system-missingmethodexception-method-not-found – Ignas May 10 '17 at 11:33

1 Answers1

0

By mistake i answered this question at the question linked in the comments (https://stackoverflow.com/a/46567611/7131186)

Here is my answer:

In my case (and it seems that this is your case too) it was a copy/paste problem. I somehow ended up with a PRIVATE constructor for my mapping profile:

using AutoMapper;

namespace Your.Namespace
{
    public class MappingProfile : Profile
    {
        MappingProfile()
        {
            CreateMap<Animal, AnimalDto>();
        }
    }
}

(take note of the missing "public" in front of the ctor)

which compiled perfectly fine, but when AutoMapper tries to instantiate the profile it can't (of course!) find the constructor!

DaBeSoft
  • 49
  • 1
  • 5