[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, 问题复现。再次发布程序,问题解决。

 

最新文章

  1. Linux时间同步,ntpdate命令、ntpd服务详解
  2. 学习 opencv---(1) opencv3.1.0 组件结构浅析
  3. java中类继承,到底继承了什么?
  4. 入门级 mongodb
  5. 设置vs2008代码区的背景色
  6. 无法解决 equal to 运算中 "Chinese_PRC_CI_AS" 和 "SQL_Latin1_General_CP1_CI_AS" 之间的排序规则冲突。
  7. 【转】Linq实现DataTable行列转换
  8. Angular报错记录
  9. LeetCode OJ 96. Unique Binary Search Trees
  10. Hibernate用Oracle的sequence生成自增Id
  11. linux 升级yum对应的python
  12. Win7桌面底部的任务栏高度的修改
  13. Attention Model(注意力模型)思想初探
  14. unity项目build成webgl时选择生成目录(解决方法)
  15. 【vue】vue +element 搭建项目,el-input 常用的验证
  16. NOI Day1线上同步赛梦游记
  17. SpringBoot 统一异常处理
  18. 数组Array.sort()排序的方法
  19. [ACM_数据结构] HDU 1166 敌兵布阵 线段树 或 树状数组
  20. July 02nd 2017 Week 27th Sunday

热门文章

  1. C# char 和string之间转换
  2. 实用的Portraiture滤镜磨皮教程
  3. fgtyn
  4. Sqlserver 自定义表类型定义,使用,删除
  5. 修复HTTP 503错误
  6. http请求提交cookie
  7. android platform下载地址
  8. Xmodem Bootloader
  9. NHibernate系列文章二十三:NHibernate查询之Criteria查询(附程序下载)
  10. jQuery利用JSON数据动态生成表格