Automapper Aftermap“找不到方法”异常

Azi*_*uth 5 c# automapper

我正在尝试使用该AfterMap方法将输入类展平为输出。输入类如下所示:

public class FooDTO {
  public string SomeFieldA { get; set; }
  public string SomeFieldB { get; set; }
  ....
  public BarDTO SomeFieldY { get; set; }
  public BazDTO SomeFieldZ { get; set; }
}

public class BarDTO {
  public string SomeOtherFieldA { get; set; }
}

public class BazDTO {
  public string YetAnotherFieldA { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

和输出类如下:

public class Foo {
  public string SomeFieldA { get; set; }
  public string SomeFieldB { get; set; }
  ....      
  public string SomeOtherFieldA { get; set; }
  public string YetAnotherFieldA { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的 AutoMapper 映射配置如下所示:

CreateMap<FooDTO, Foo>()
   .AfterMap((src, dest, ctx) => ctx.Mapper.Map(src.SomeFieldY, dest))
   .AfterMap((src, dest, ctx) => ctx.Mapper.Map(src.SomeFieldZ, dest));
CreateMap<BarDTO, Foo>();
CreateMap<BazDTO, Foo>();
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我尝试运行应用程序时,出现以下未处理的异常:

 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.MissingMethodException: Method not found: 'AutoMapper.IMappingExpression`2<!0,!1> AutoMapper.IMappingExpression`2.AfterMap(System.Action`3<!0,!1,AutoMapper.ResolutionContext>)'.
Run Code Online (Sandbox Code Playgroud)

我是否缺少其他一些配置?如何让我的代码工作?

Azi*_*uth 5

正如 Lucian Bargaoanu 提到的,这是由于 Nuget 软件包版本不匹配造成的。当我将另一个项目升级到版本 9.0.0 后,它就开始工作了。