[TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0
System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +180
System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +192
System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) +115
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +426
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +103
System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) +64
WebActivator.AssemblyExtensions.GetActivationAttributes(Assembly assembly) +132
WebActivator.ActivationManager.RunActivationMethods() +216
WebActivator.ActivationManager.RunPreStartMethods() +43
WebActivator.ActivationManager.Run() +69

原因: In .Net 4.5 the ExtensionAttribute class was moved from System.Core to mscorlib. 
        ExtensionAttribute 类在4.5中从System.Core迁移到mscorlib中,项目运行时会按4.5的方法寻找导致异常。
       有人会说,项目都是按4.0编译的,4.5也卸载了,为什么还会出现此问题?原因在于引用的第三方类库可能还是关联的4.5版本,比如我遇到这个问题是由于Entityframework引用了4.5版本导致的,而4.0和4.5从dll属性中看不出来 参考:
http://www.cnblogs.com/gossip/p/3527970.html
http://stackoverflow.com/questions/13748055/could-not-load-type-system-runtime-compilerservices-extensionattribute-from-as
http://stackoverflow.com/questions/16039990/runtime-exception-with-net-4-5-build-could-not-load-type-system-runtime-compi 解释:System.Runtime.CompilerServices.ExtensionAttribute 在 .net 4.0里 在 System.Core.Dll里, 在 .net 4.5里则被移到了 mscorlib 中。
System.Core.Dll的版本显示的 4.0.0.0 版,但实际上已经被 .net 4.5替换,里面没有ExtensionAttribute 类。

未替换的版本在目录“C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0”下,用Reflector可以看到,里面有ExtensionAttribute类。


解决的方法:
解决方法1: 在用户的机器上安装 .net 4.5。 对OS的要求是:

Windows 7 SP1(x86 和 x64)
Windows Server 2008 R2 SP1 (x64)
Windows Server 2008 SP2(x86 和 x64)


解决方法2: 自己编译混淆的机器上,仅安装了.net 4.0, 未安装 4.5。

后记:把 4.5卸载后, 重新安装了 4.0, 问题复现。再次发布程序,问题解决。

 

Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute'的更多相关文章

  1. "Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b7

    1.错误背景 系统安装了.net framework4.0.4.5,项目先使用VS2013(4.5)开发,后来又重新用VS2010开发(4.0),运行时出现这个错误 2.错误原因 In .Net 4. ...

  2. Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib 的一种情形

    没有引用任何.net 4.5的东西,也没有引用 Newtonsoft.dll,原因是引用了微软的tlb类型库,引用方法如 https://www.cnblogs.com/nanfei/p/108798 ...

  3. 缺少编译器要求的成员“System.Runtime.CompilerServices.ExtensionAttribute..ctor” 解决方案

    我自己使用的解决方法 错误产生环境及非完美解决办法 错误提示:缺少编译器要求的成员"System.Runtime.CompilerServices.ExtensionAttribute..c ...

  4. 缺少编译器要求的成员“System.Runtime.CompilerServices.ExtensionAttribute..ctor” 解决方案

    静态类中添加如下.此方法本人测试有效. //缺少编译器要求的成员“ystem.Runtime.CompilerServices.ExtensionAttribute..ctor” namespace  ...

  5. 解决System.Runtime.CompilerServices.ExtensionAttribute..ctor 与 ‘ExtensionAttribute’ is ambiguous in the namespace ‘System.Runtime.CompilerServices’ 问题

    从VSS上获取以前的老项目,编译时报System.Runtime.CompilerServices.ExtensionAttribute..ctor 网上写的“删除 Newtonsoft.Json.N ...

  6. 未能从程序集“mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中加载类型“System.Runtime.CompilerServices.TuppressIldasmAttribute”。已解决

    "/"应用程序中的服务器错误. 未能从程序集"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77 ...

  7. Json序列化提示缺少编译器要求的成员“ystem.Runtime.CompilerServices.ExtensionAttribute..ctor”

    //缺少编译器要求的成员“ystem.Runtime.CompilerServices.ExtensionAttribute..ctor” namespace System.Runtime.Compi ...

  8. System.Runtime.CompilerServices.Unsafe

    System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Un ...

  9. Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c

    错误: Could not load type 'System.Reflection.AssemblySignatureKeyAttribute' from assembly 'mscorlib, V ...

随机推荐

  1. 超链接实现post方式提交

    思路:如果想要超链接实现post方式提交,必须借助表单.下面得两种方式,一种是借助显示的form表单,一种是借助隐式的form表单方式一:将超链接放到一个form表单中,或者超链接本身就在一个form ...

  2. Java里Serializable的那些事

    本文为原创文章,欢迎转载,但请注明出处http://www.cnblogs.com/yexiubiao/p/5014015.html,未在文章页面明显位置给出原文连接的,将保留追究法律责任的权利. 通 ...

  3. [JavaScript]顺序的异步执行

    我们知道,在适用js的时候,程序是单线程执行的,而且如果遇到阻塞就会将浏览器卡死. 能否异步的执行,让程序不再卡呢? 可以,用setTimeout. 但是,问题又来了,如果我有这样的要求: 执行一个函 ...

  4. springMVC发送邮件

    springMVC发送邮件 利用javax.mail发送邮件,图片与附件都可发送 1,Controller类 package com.web.controller.api; import javax. ...

  5. php使用ajax导出CSV或者EXCEl(thinkphp)方法

    首先我强烈推荐看到这篇文章的你将导出文件设置为csv格式的文件 实际测试导出csv文件的速度是excel文件的10几倍左右 首先我先介绍csv文件的导出的方法: 如果你单纯是在数据导出界面上通过用户点 ...

  6. Redis安装手册

    转载请注明出处:http://www.cnblogs.com/robinjava77/p/5465146.html (Robin) 1)下载redis:wget http://download.red ...

  7. C#有关数组内存的释放及动态数组问题

    一.数组内存释放问题 数组内存的释放可以按照如下语句实现: string [] aa=new string[2]; aa[0]="A"; aa[1]="B"; ...

  8. R12将银行和分行都使用TCA管理

    R12将银行和分行都使用TCA管理,后台保存在HZ_PARTIES . 银行帐号:如果是付款或者是收款(本公司的帐号,内部帐号),都保存在ce_bank_accounts,ce_bank_acct_u ...

  9. editplus工具支持sql高亮提示

    editplus默认不识别sql关键件,添加文件使其对sql高亮提示. 首先就是要自己编写一段代码,存为.stx 文件(例如sql.stx) 然后在editplus的菜单栏 工具-> 配置用户工 ...

  10. Python-lambda函数,map函数,filter函数

    lambda函数主要理解: lambda 参数:操作(参数). lambda语句中,冒号前是参数,可以有多个,用逗号隔开,冒号右边的返回值.lambda语句构建的其实是一个函数对象 map函数: ma ...