【发布时间】:2018-02-08 16:03:08
【问题描述】:
使用 .NET 4.6.2 和较旧的网站(不是 Web 应用程序)项目。如果我清除 BIN 目录,然后构建并运行它可以工作,但有时在多次构建和运行后,它会失败并出现此错误。
Server Error in '/' Application.
Cannot load a reference assembly for execution.
....
[BadImageFormatException: Cannot load a reference assembly for execution.]
[BadImageFormatException: Could not load file or assembly 'netfx.force.conflicts' or
one of its dependencies. Reference assemblies should not be loaded for execution.
They can only be loaded in the Reflection-only loader context.
(Exception from HRESULT: 0x80131058)]
....
当网站项目使用的库开始引入 netstandard 2.0 时,有什么技巧可以让网站项目正常工作吗?
此外,似乎需要此程序集绑定重定向才能使其运行,但 nuget 添加了对旧版本 4.1.1.0 的重定向。除了在大多数 nuget 更新后手动编辑此行之外,有关如何解决此问题的任何建议?
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
如果将项目迁移到 Web-Application 项目,所有这些问题都会消失吗?
【问题讨论】:
-
您可能已经知道这一点,但我只想说,我在 x64 机器上尝试使用 32 位 dll 时看到了这一点。从网站转换为网络应用程序项目类型时,我认为这不会消失。
-
伊恩,你有什么运气吗?使用与您相同的设置时,我遇到了同样的问题:4.6.2 ASP.NET Web Api 中的 .NET 标准库。
-
@AdamScharp 还没有运气,每次发生时仍然手动删除
bin目录。在这种情况下,运行时版本问题似乎与 MongoDB 有关。 -
在删除 bin 目录之前是否需要关闭 Visual Studio?
-
@IanMercer 我通过删除 web 项目文件夹中的 bin 文件夹解决了这个问题。我有 VS2017 + .NET 标准库 2.02 + .NET 4.6.1
标签: c# asp.net web-site-project .net-standard