C# 无法从程序集“mscorlib,版本 = 4.0.0.0”中加载类型“System.Runtime.CompilerServices.ExtensionAttribute”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19933643/
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
Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0 Error
提问by dan1
My .NET site is working fine on Localhost. But, on my Server. I get this error.
我的 .NET 站点在 Localhost 上运行良好。但是,在我的服务器上。我收到这个错误。
"Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."
“无法从程序集 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 加载类型 'System.Runtime.CompilerServices.ExtensionAttribute'。”
(Can't post screenshot, due to Stack Overflow policy)
(由于堆栈溢出政策,无法发布屏幕截图)
It's something to do with asp:ScriptManager. I have used it before on the same server, but now, it's showing an error.
这与asp:ScriptManager 有关。我以前在同一台服务器上使用过它,但现在显示错误。
PS: When I remove Scriptmanager, the code runs fine.
PS:当我删除 Scriptmanager 时,代码运行良好。
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
版本信息:Microsoft .NET Framework 版本:4.0.30319;ASP.NET 版本:4.0.30319.272
采纳答案by JaredPar
This error comes about when you compile an application against .Net 4.5 but then run it on a machine that only has 4.0 installed.
当您针对 .Net 4.5 编译应用程序,然后在仅安装了 4.0 的机器上运行它时,就会出现此错误。
In .Net 4.5 the ExtensionAttribute
class was moved from System.Core to mscorlib. There is a type forwarder in System.Core that points to the new location in mscorlib. If you compile an app against 4.5 it will expect to find ExtensionAttribute
in mscorlib. If you then run it against 4.0 you will get this exception because in actually lives in System.Core in 4.0
在 .Net 4.5 中,ExtensionAttribute
该类从 System.Core 移至 mscorlib。System.Core 中有一个类型转发器,指向 mscorlib 中的新位置。如果您针对 4.5 编译应用程序,它将期望ExtensionAttribute
在 mscorlib 中找到。如果您然后针对 4.0 运行它,您将收到此异常,因为实际上存在于 4.0 中的 System.Core
To fix this either deploy 4.5 to the server or make sure that you build against 4.0
要解决此问题,请将 4.5 部署到服务器或确保针对 4.0 构建
回答by Hisen
JUST install microsoft framework v4.5 or higher on you pc or server it's worked for me very well
只需在您的 PC 或服务器上安装 microsoft framework v4.5 或更高版本,它对我来说效果很好