在我的webapi项目中,我对Automapper配置有一个例外,但是我不清楚生成它的原因是什么。
我正在使用自动映射器配置文件,让我用代码解释,我有类似的东西:
//Define profiles for mapping in a class
using AutoMapper;
using somedirectory.Service.WebAPI.WCF; //references
using somedirectory.Service.WebAPI.Models; //models
namespace somedirectory.Service.WebAPI.Mapper
{
public class CompanyProfile : Profile{
protected override void Configure(){
Mapper.CreateMap<myModel, myDTO> () //Custom mapping
.ForMember(dto => dto.myProperty, model => model.ResolveUsing(m => m.myProperty))
//Other mapping
.ReverseMap(); //This would be enough to reverse map
}
}
}
//Register profiles by layer in a class
using AutoMapper;
namespace somedirectory.Service.WebAPI.Mapper{
public class AutoMapperWebapiConfiguration{
public static void Configure(){
Mapper.Initialize(cfg => {
cfg.AddProfile<CompanyProfile>();
// or cfg.AddProfile(new CompanyProfile());
});
}
}
}
//Set configuration on Global.asax by layer
protected void Application_Start(){
AutoMapperWebapiConfiguration.Configure(); //This can be set on WebApiConfig.cs
}
这是一个基本的自动映射器配置,必须正常工作。 但是当Application_Start运行时,会生成此异常:
{"Could not load file or assembly 'System.Reflection.TypeExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.":"System.Reflection.TypeExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}
在google中搜索时,我发现这可能是与框架版本有关的错误,但是我不相信我使用的是框架的4.6.7版本和Automapper的4.1.1版本。应该可以。
所以,我认为我的配置有问题。但我看不到。
有什么想法,建议或帮助吗? 我非常感谢您的帮助,我只是一个初学者。
来源: