ABP項目:未能加載文件或程序集“Castle.Core, Version=4.1.1.0, Culture=neutral”或它的某一個依賴項。找到的程序集清單定義與程序集引用不匹配

運行ABP MVC 版本的singlepage時,使用code first方式遷移數據庫時,提現版本不對,如下所示:

PM> add-migration InitialCreate
System.IO.FileLoadException: 未能加載文件或程序集“Castle.Core, Version=4.1.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc”或它的某一個依賴項。找到的程序集清單定義與程序集引用不匹配。 (異常來自 HRESULT:0x80131040)
文件名:“Castle.Core, Version=4.1.1.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc” ---> System.IO.FileLoadException: 未能加載文件或程序集“Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc”或它的某一個依賴項。找到的程序集清單定義與程序集引用不匹配。 (異常來自 HRESULT:0x80131040)
文件名:“Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc”

警告: 程序集綁定日誌記錄被關閉。
要啓用程序集綁定失敗日誌記錄,請將註冊表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)設置爲 1。
注意: 會有一些與程序集綁定失敗日誌記錄關聯的性能損失。
要關閉此功能,請移除註冊表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。

   在 System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   在 System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
   在 System.Reflection.RuntimeMethodInfo.GetParametersNoCopy()
   在 System.Reflection.RuntimePropertyInfo.GetIndexParametersNoCopy()
   在 System.Reflection.RuntimePropertyInfo.GetIndexParameters()
   在 System.Data.Entity.Internal.DbSetDiscoveryService.<>c.<GetSets>b__4_1(PropertyInfo p)
   在 System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   在 System.Data.Entity.Internal.DbSetDiscoveryService.GetSets()
   在 System.Data.Entity.Internal.DbSetDiscoveryService.InitializeSets()
   在 System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
   在 Abp.EntityFramework.AbpDbContext..ctor(String nameOrConnectionString)
   在 Sample.ABPMVCAngular.EntityFramework.ABPMVCAngularDbContext..ctor() 位置 D:\CodeRepository\Learning\ABP\Sample.ABPMVCAngular\5.0.0\src\Sample.ABPMVCAngular.EntityFramework\EntityFramework\ABPMVCAngularDbContext.cs:行號 27
--- 引發異常的上一位置中堆棧跟蹤的末尾 ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Data.Entity.Infrastructure.DbContextInfo.CreateInstance()
   在 System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo, Func`1 resolver)
   在 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase)
   在 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   在 System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration)
   在 System.Data.Entity.Infrastructure.Design.Executor.CreateMigrationScaffolder(DbMigrationsConfiguration configuration)
   在 System.Data.Entity.Infrastructure.Design.Executor.ScaffoldInternal(String name, DbConnectionInfo connectionInfo, String migrationsConfigurationName, Boolean ignoreChanges)
   在 System.Data.Entity.Infrastructure.Design.Executor.Scaffold.<>c__DisplayClass0_0.<.ctor>b__0()
   在 System.Data.Entity.Infrastructure.Design.Executor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
   在 System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(Action action)

排查過程,根據提示,是找不到 Version=4.1.1.0的Castle.Core程序集。

  • 查看.EntityFramework與.Core項目的nuget程序包,發現Castle.Core都是4.4.0版本
  • 兩個項目下的app.config文件中引用的是4.1.1.0版本,而packages.config中用的都是4.4.0版本,如下,得出的結論:系統中加載使用的的是4.4.0版本。而配置中還是使用舊的4.1.1.0版本。
--app.config
<dependentAssembly>
        <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
</dependentAssembly>

--packages.config
<package id="Castle.Core" version="4.4.0" targetFramework="net461" />

結論:

只需要將.EntityFramework與.Core項目中的app.config配置改爲4.4.0版本即可,如下

      <dependentAssembly>
        <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.4.0" />
      </dependentAssembly>

 

發佈了48 篇原創文章 · 獲贊 3 · 訪問量 32萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章