"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.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属性中看不出来

3、解决方法
      拿entityframework举例,用nuget下载entityframework,生成的packages\EntityFramework.6.0.2\lib文件夹中会有net40和net45两个文件夹,引用.net4.0文件夹中的dll即可

posted @ 2014-01-21 10:59    阅读(6279)  评论(1编辑  收藏  举报