"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即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib 的一種情形 Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not mat Could not load file or assembly 'Microsoft.Extensions.Hosting.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definiti 必須添加對程序集“System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”的引用 Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its depe 創建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置節處理程序時出錯: 未能加載文件或程序集“System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一個依賴項。系統沒找到指定的文件 未能加載文件或程序集“System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken Microsoft.VisualStudio.TeamFoundation.VersionControl, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 未能加載文件或程序集“System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51”或它的某一個依賴項。找到的程序集清單定義與程序集引用不匹配。
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM