什么会导致程序集构建版本和运行时版本不同?
我有一个 C# 解决方案、两个项目、一个 winforms 和一个 dll,其中 winforms 项目引用了 dll,并且我已将项目中我所知道的所有内容设置为框架版本 2.0,但在启动时我仍然收到此 FileLoadException :
混合模式程序集是针对 运行时版本“v2.0.50727” 并且无法在4.0中加载 运行时无需额外 配置信息。
我配置的设置是:
- 属性 - 目标框架是 .NET Framework 2.0
- 项目链接的所有引用均使用 .NET 2.0 构建。
- 配置管理器中指示是否应构建项目的所有复选框均已选中。
我也尝试清理解决方案,删除地图项目\bin\,但是当解决方案重新编译并运行时,仍然抛出异常。我的计算机上安装了 Visual Studio 2010 Ultimate,同时安装了 .NET 4.0 和 .NET 3.5 SP1。
我肯定错过了导致此异常的设置,但我不知道,有人知道吗?我只是希望它使用 .NET 2.0,而不是 .NET 4.0。
I have a C# solution, two projects, a winforms and a dll, where the winforms project references to the dll, and I've set everything I know of in the project to the framework version 2.0, yet I still get this FileLoadException on startup:
Mixed mode assembly is built against
version 'v2.0.50727' of the runtime
and cannot be loaded in the 4.0
runtime without additional
configuration information.
The settings I configured are:
- Properties - Target framework is .NET framework 2.0
- All references the project links to are built with .NET 2.0
- All checkboxes in the Configuration manager indicating whether the projects should be built are checked.
Also I've tried cleaning the solution, deleting the map project\bin\, but when the solution is recompiled and run, the exception is still thrown. On my machine I have Visual Studio 2010 Ultimate with both .NET 4.0 and .NET 3.5 SP1 installed.
I must have missed a setting which causes this exception, but I'm unaware of it, does anyone know ? I just want it to use .NET 2.0, not .NET 4.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要尝试强制它在 CLR 2.x 中加载,您可能需要(在您的 app.config 文件中):
这通常仅在您使用混合模式时才需要,并强制加载器进行操作。
To try to force it to load in CLR 2.x, you may need to have (in your app.config file):
This is generally only required when you have mixed-mode, and forces the hand of the loader.
好吧,尽管您努力以 2.0 为目标,但它仍在运行 4.0 CLR。它正在抱怨 C++/CLI 程序集,大概是您引用的 DLL。需要一个 .config 文件来说服 CLR 可以使用 .NET 4.0 加载该 DLL,即使它可能包含需要使用 2.0 的非托管代码,请搜索“useLegacyV2RuntimeActivationPolicy”。这将解决该 DLL 的 4.0 加载问题。
它仍然可以加载 4.0 的唯一其他原因是一个 .config 文件,该文件表示它应该使用 4.0,
元素。为了使这一点更加直观,您可以使用 Fuslogvw.exe 工具,将其设置为记录所有绑定。如果您无法理解它,请将 EXE 的绑定跟踪复制/粘贴到您的问题中。Well, it's running the 4.0 CLR in spite of your efforts to target 2.0. It's bitching about a C++/CLI assembly, presumably the DLL that you referenced. A .config file is required to convince the CLR that it is okay to use .NET 4.0 to load that DLL, even though it might contain unmanaged code that expects 2.0 to be used, google "useLegacyV2RuntimeActivationPolicy". That would solve the 4.0 loading problem for that DLL.
About the only other reason that it could still load 4.0 is a .config file that says it should use 4.0,
<supportedRuntime>
element. To make this more visual you can use the Fuslogvw.exe tool, set it up to log all bindings. Copy/paste the binding trace for your EXE into your question if you can't make sense of it.