Automapper v3.3.1.0 缺少类型映射配置或不支持的映射

Automapper v3.3.1.0 Missing type map configuration or unsupported mapping

我收到错误缺少类型映射配置或不支持的映射。

AutoMapper 版本:v3.3.1.0

我的代码是:

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>();
    }
}

当我尝试调用映射时:

   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);
    }

我收到错误:

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

如果我调试 Global.asax 我在代码中得到错误:

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'.

你需要一个初始化方法。

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

如果多次调用 Initialize 方法,它会清除所有以前的配置。