Patrick
Patrick

Reputation: 2781

Automapper v3.3.1.0 Missing type map configuration or unsupported mapping

I get the error Missing type map configuration or unsupported mapping.

Version of AutoMapper: v3.3.1.0

My code is:

Global.asax

protected void Application_Start()
{
   AutoMapperWebConfig.RegisterMappings();
   AutoMapperServiceConfig.RegisterMappings();
}

AutoMapperWebConfig:

public class AutoMapperWebConfig
{
    public static void RegisterMappings()
    {
        Mapper.Initialize(cfg =>
        {
            cfg.AddProfile<DtoToViewModelMappingProfile>();
        });
    }
}

AutoMapperServiceConfig:

public class AutoMapperServiceConfig
{
    public static void RegisterMappings()
    {
        Mapper.Initialize(cfg =>
        {
            cfg.AddProfile<DomainToDtoMappingProfile>();
        });
    }
}

DtoToViewModelMappingProfile:

public class DtoToViewModelMappingProfile : Profile
{
    public override string ProfileName
    {
        get { return "DtoToViewModelMappings"; }
    }

    protected override void Configure()
    {
        Mapper.CreateMap<PartnerSearchResultDTO, PartnerSearchResultVM>();
    }
}

DomainToDtoMappingProfile:

public class DomainToDtoMappingProfile : Profile
{
    public override string ProfileName
    {
        get { return "DomainToDtoMappings"; }
    }

    protected override void Configure()
    {
        Mapper.CreateMap<Partner, PartnerSearchResultDTO>();
    }
}

When I try to invoke the mapping:

   public virtual PartialViewResult Search(PartnerSearchVM partnerSearch)
    {
        var partnerServices = new PartnerService();

        var partnersDTO = partnerServices.Search(partnerSearch.Service_Id, partnerSearch.Brand_Id, partnerSearch.LocationLatitude, partnerSearch.LocationLongitude, 20);

        var partnersVM = Mapper.Map<IList<PartnerSearchResultDTO>, IList<PartnerSearchResultVM>>(partnersDTO);

        return PartialView(MVC.Partner.Views.List, partnersVM);
    }

I get the error:

Missing type map configuration or unsupported mapping.

Mapping types:
  PartnerSearchResultDTO -> PartnerSearchResultVM
  PRJ.Services.DtoModels.PartnerSearchResultDTO ->       PRJ.ViewModels.PartnerSearchResultVM

Destination path:
IList`1[0]

Source value:
PRJ.Services.DtoModels.PartnerSearchResultDTO

If I debug the Global.asax I get the error in the code:

cfg.AddProfile<>

"Mapper.cs not found"

Locating source for 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs'. Checksum:  MD5 {28 13 88 2d fa c bf 90 0 c9 9c 25 64 11 3d 36}
The file 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs' does not exist.
Looking in script documents for 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs'...
Looking in the projects for 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs'.
The file was not found in a project.
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio  12.0\VC\crt\src\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src\vccorlib\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\src\mfc\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio  12.0\VC\atlmfc\src\atl\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include'...
Looking in directory 'C:\'...
The debug source files settings for the active solution indicate that the  debugger will not ask the user to find the file:     c:\dev\AutoMapper\src\AutoMapper\Mapper.cs.
The debugger could not locate the source file 'c:\dev\AutoMapper\src\AutoMapper\Mapper.cs'.

Upvotes: 1

Views: 1390

Answers (1)

Bryan Crosby
Bryan Crosby

Reputation: 6554

You need to have one initialize method.

Mapper.Initialize(cfg =>
{
    cfg.AddProfile<DtoToViewModelMappingProfile>();
    cfg.AddProfile<DomainToDtoMappingProfile>();
});

The Initialize method clears out any previous configuration if you call it more than once.

Upvotes: 2

Related Questions