C# “此程序集是由比当前加载的运行时更新的运行时构建的,无法加载”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10607095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded"
提问by Nick Myers
I'm getting the error: "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."
我收到错误消息:“此程序集是由比当前加载的运行时更新的运行时构建的,无法加载。”
I have a .NET 4.0 dll project that is being called by a .NET 2.0 project. Is there a way to reconcile the difference in framework?
我有一个 .NET 2.0 项目正在调用的 .NET 4.0 dll 项目。有没有办法调和框架的差异?
采纳答案by Jon Skeet
I have a .NET 4.0 dll project that is being called by a .NET 2.0 project. Is there a way to reconcile the difference in framework?
我有一个 .NET 2.0 项目正在调用的 .NET 4.0 dll 项目。有没有办法调和框架的差异?
Not that way round, no. The .NET 4 CLR can load .NET 2 assemblies (usually - there are a few exceptions for mixed-mode assemblies, IIRC), but not vice versa.
不是那样,不。.NET 4 CLR 可以加载 .NET 2 程序集(通常 - 混合模式程序集有一些例外,IIRC),但反之则不然。
You'll either have to upgrade the .NET 2 project to .NET 4, or downgrade the .NET 4 project to .NET 3.5 (or earlier).
您要么必须将 .NET 2 项目升级到 .NET 4,要么将 .NET 4 项目降级到 .NET 3.5(或更早版本)。
回答by IAbstract
Since only one version of the run-time can be loaded into a process (although, as others have alluded, backwards loading - 4.0 loading 2.0 - is okay), you have a few options:
由于只能将一个版本的运行时加载到进程中(尽管正如其他人所暗示的,向后加载 - 4.0 加载 2.0 - 是可以的),您有几个选择:
- Upgrade the .Net 2.0 project
- Wrap the .Net 2.0 project (if the source is not yours)
- Downgrade the .Net 4.0 project
- Load the .Net 4.0 project into it's own process (I believe this can work - but will take a bit of effort, IMO)
- 升级 .Net 2.0 项目
- 包装 .Net 2.0 项目(如果源不是你的)
- 降级 .Net 4.0 项目
- 将 .Net 4.0 项目加载到它自己的进程中(我相信这可以工作 - 但需要一些努力,IMO)
回答by aditya
You'll either have to upgrade the .NET 2 project to .NET 4, or downgrade the .NET 4 project to .NET 3.5 (or earlier).
您要么必须将 .NET 2 项目升级到 .NET 4,要么将 .NET 4 项目降级到 .NET 3.5(或更早版本)。
How do you upgrade the .net version? I am not sure where to and what to specify. Please help.
你如何升级.net版本?我不确定要指定的位置和内容。请帮忙。
Edit: I found the answer myself. Select the project, right click and choose Property Pages. There you can select framework version. or select the project and click Shift+F4
编辑:我自己找到了答案。选择项目,右键单击并选择“属性页”。在那里您可以选择框架版本。或选择项目并单击Shift+F4
回答by Md Kauser Ahmmed
Change INSTALL_UTIL_HOMEdirectory from C:\WINDOWS\Microsoft.NET\Framework\v2.0to C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319for installing the service. This error mainly occurs for version mismatch.
将INSTALL_UTIL_HOME目录从更改C:\WINDOWS\Microsoft.NET\Framework\v2.0为C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319以安装服务。此错误主要发生在版本不匹配上。
回答by Ziggler
I got same error message. I was giving
我收到了同样的错误信息。我在给
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe "C:\MyService\MyService.exe"
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe "C:\MyService\MyService.exe"
Instead of
代替
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "C:\MyService\MyService.exe"
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "C:\MyService\MyService.exe"
回答by ObeOne
I got this error too, but my problem was that I was using an older version of GACUTIL.EXE.
我也遇到了这个错误,但我的问题是我使用的是旧版本的GACUTIL.EXE.
Once I had the correct GACUTILfor the latest .NETversion installed, it worked fine.
一旦我安装GACUTIL了最新.NET版本的正确版本,它就可以正常工作。
The error is misleading because it makes it look like it's the DLL you're trying to register that incorrect.
该错误具有误导性,因为它看起来像是您尝试注册的 DLL 不正确。
回答by abdul basit
Its .net Version mismatch of the dll so try changing to from in app.config or web.config. Generally have a higher Framework than lower because when we add system's dll to the lower version built .net application so it won't work therefore just change to the higher version
它的 .net 版本与 dll 不匹配,因此尝试在 app.config 或 web.config 中更改为 from。通常有一个更高的框架而不是更低的,因为当我们将系统的 dll 添加到低版本构建的 .net 应用程序时,它不会工作,因此只需更改为更高版本
回答by Prof
Interestingly, I kept getting that error. What fixed it for me was creating a config called gacutil.exe.configin the same directory as gacutil.exe. The config content (a text file) were:
有趣的是,我一直收到那个错误。对我来说修复它的是在与gacutil.exe相同的目录中创建一个名为gacutil.exe.config的配置。配置内容(一个文本文件)是:
<?xml version ="1.0"?> <configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
</startup> </configuration>
I'm posting this here for reference and ask if anyone knows what's actually happening under the hood. I'm not claiming this is the "proper" way of doing it
我在此发布以供参考,并询问是否有人知道幕后实际发生了什么。我并不是说这是做这件事的“正确”方式
回答by user2209195
If you have already tried all the other logical solutions on this page, then double check this. In my app.config I had a reference to an old framework.
如果您已经尝试过此页面上的所有其他逻辑解决方案,请仔细检查。在我的 app.config 中,我引用了一个旧框架。
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
should have been
本来应该
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
The project tab correctly showed v4.0 but the app.config was not committed to our repo with that change. To fix it, I changed the framework to something else and back to 4.0 again, which updated my app.config file.
项目选项卡正确显示了 v4.0,但 app.config 未通过该更改提交到我们的存储库。为了修复它,我将框架更改为其他内容并再次返回到 4.0,这更新了我的 app.config 文件。
回答by Steven Wolfe
This error may also be triggered by having the wrong .NET framework version selected as the default in IIS.
此错误也可能是由于在 IIS 中选择了错误的 .NET 框架版本作为默认版本而触发的。
Click on the root node under the Connectionsview (on the left hand side), then select Change .NET Framework Versionfrom the Actionsview (on the right hand side), then select the appropriate .NET version from the dropdown list.
单击Connections视图(左侧)下的根节点,然后从Actions视图(右侧)中选择Change .NET Framework Version,然后从下拉列表中选择适当的 .NET 版本。

