How to Solve Error: Missing type map configuration or unsupported mapping

Error: Missing type map configuration or unsupported mapping

□ Background

When saving the View Model into Domain Model, an error occurred in AutoMapper.

 

□ Analysis

1. A mapping has been established in the Profile class derived from AutoMapper:
Mapper.CreateMap<SomeDomainModel, SomeViewModel>();

 

2. The classes derived from Profile have also been initialized:

    public  static  class AutoMapperConfiguration
    {
        public  static  void Configure()
        {
            Mapper.Initialize(x => x.AddProfile<SomeProfile>());
 
        }
    }

3. Also registered in the global:

        protected  void Application_Start()
        {
            //Configuration mapping
            AutoMapperConfiguration.Configure();
        }

4. The unit test also passed:

    [TestClass]
    public  class AutoMapperConfigurationTester
    {
        [TestMethod]
        public  void TestMethod1()
        {
            AutoMapperConfiguration.Configure();
            Mapper.AssertConfigurationIsValid();
        }
    }

□ Solution

When actually mapping, replace AutoMapper.Mapper.Map<Source, Destination> with AutoMapper.Mapper.DynamicMap<Source, Destination>

DomainModel someDomainModel = AutoMapper.Mapper.Map<ViewModel, DomainModel>(someViewModel);

Change to:

DomainModel someDomainModel = AutoMapper.Mapper.DynamicMap<ViewModel, DomainModel>(someViewModel);    

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *