为什么AutoMapper v3不能工作,因为它正在寻找v2.2.1.0?

12

我刚刚通过nuGet在一个新项目上安装了AutoMapper,但是当我运行代码时,出现了以下错误:

无法加载文件或程序集“AutoMapper, Version=2.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005”或其依赖项之一。 找到的程序集清单定义与程序集引用不匹配。(HRESULT 异常: 0x80131040)

为什么它要寻找Version=2.2.1.0,并且我该怎么办?回退到那个版本吗?

4个回答

12
你可能只需要为AutoMapper添加一个绑定重定向,因为你的某个引用特别要求2.2版本。应该这样做:
 <dependentAssembly>
      <assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" 
                     culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
    </dependentAssembly>

事实上,我刚刚更新到了3.0版本,并遇到了你所遇到的问题。通过添加这个绑定重定向,我已经解决了这个问题。如果你有 .NET 反编译器,你可能可以看到是什么引用了这个问题,但这可能相当学术化。 - dove

4

尝试卸载并重新安装AutoMapper。

如果您的解决方案中有多个项目,则很可能已经在其中一个项目中安装了版本2.2.1.0。但是,最新版本的AutoMapper是3.0.0,这就是为什么您会遇到问题的原因。


这是完全可能的。我今晚再次开始编写代码时会仔细检查。 - ProfK

1

问题:

无法加载文件或程序集“AutoMapper,Version=3.2.1.0,Culture=neutral,PublicKeyToken=be96cd2c38ef1005”或其某个依赖项。 找到的程序集清单定义与程序集引用不匹配。 (HRESULT 异常: 0x80131040)

解决方案:

在您的 app.config 文件中添加 assemblyBinding:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="AutoMapper" publicKeyToken="be96cd2c38ef1005" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.2.1.0" newVersion="3.3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

清理、重新构建解决方案,微笑!:-)


0

我曾经遇到过同样的错误,通过将应用程序池的“启用32位应用程序”设置为True,我成功地解决了这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接