2017-09-21 115 views
1
public class AutoMapperBootstrap : AutoMapper.Profile 
{ 
    protected override void Configure() 
    { 
     //ReplaceMemberName("Z", "A"); 
     //CreateMap<Source, Destination>(); 
    } 
    public override string ProfileName 
    { 
     get { return this.GetType().Name; } 
    } 
} 

我有这个AutoMapperBootstrap类在我的MVC应用程序的文件夹App_Start。覆盖无效配置()给编译错误“AutoMapperBootstrap.Configure()“:发现没有覆盖合适的方法”

中的“配置”的方法是让编译器错误 - “没有合适的方法重写”,我得到的配置方法,而不是摘要名称

我已经看到了在StackOverflow上压倒一切的配置方法的例子很多错误自定义Automapper配置文件中的配置文件。

但为什么我得到这个编译器错误。

请让我知道我在做什么错误?

或者它是最新版本的Automapper没有这个配置方法被覆盖。

注意:我已将最新的Automapper版本6.1.1.0从Nuget下载到我的应用程序中。

+0

尝试从'Configure'移动你的代码,构造 – ASpirin

回答

2

更新版本的AutoMapper have a different method用于设置配置文件。我正在使用这里描述的方法在.net项目的类库中设置自动化。

namespace Project.Helpers 
{ 
    public class NewMapperProfile : Profile 
    { 
     public NewMapperProfile() 
     { 
      CreateMap<ClassA, ClassB>(); 
     } 
    } 
} 
+0

所以,我也发现了较新版本的AutoMapper的不使用“覆盖配置”的方法了。另外,我测试了上面创建配置文件的方法,它可以工作。我希望这有帮助! –