简体   繁体   中英

Automapper missing type map configuration or unsupported mapping (automapper 6.1.1)

This is what I am trying to do and getting exception on this very line:

Mapper.Map<CreditCard>(cardVM);

While other mappings are working perfectly but these two entities aren't here's models of both :

[Serializable]
    public class CreditCard : BaseEntity
    {
        public long UserId { get; set; }
        public string BankToken { get; set; }
        public string CardNumber { get; set; }
        public User User { get; set; }
    }


[Serializable]
    public class CreditCardVM
    {
        public Guid? UID { get; set; }
        public long UserId { get; set; }
        public string BankToken { get; set; }
        public string CardNumber { get; set; }
        public string PaymentMethodUId { get; set; }
        public User User { get; set; } 
    }

But still getting exception "Automapper missing type map configuration or unsupported mapping"

What about checking Automapper configurations initiation, maybe your mappings configutations are not initialized.

So, check the application start configuration in your startup project, like in web application you have to check "application_start in Global.asax"

protected void Application_Start()
{
    AutoMapperConfigurator.Initialize();
}

Thanks guys , but here is what I missed .

public class CreditCardAutoMapperProfile : Profile
    {
        public CreditCardAutoMapperProfile()
        {
            CreateMap<Data.Entities.CreditCard, CreditCardVM>();
        }
    }

And it starts working :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM