web-dev-qa-db-ja.com

ファイルまたはアセンブリAutofac、バージョン= 3.3.0.0を読み込めませんでした

プロジェクトをAutofac2.6.3.862から3.4.0.0にアップグレードした後、次のエラーが発生しました。ソリューション内のどのプロジェクトにも、Autofac3.3.0.0への参照を追加しませんでした。

=== Pre-bind state information ===
LOG: DisplayName = Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da
 (Fully-specified)
LOG: Appbase = file:///C:/Projects/Drive/temp/drive/Src/Web/
LOG: Initial PrivatePath = C:\Projects\Drive\temp\drive\Src\Web\bin
Calling Assembly : Autofac.Configuration, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\Drive\temp\drive\Src\Web\web.config
LOG: Using Host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da
LOG: Attempting download of new URL file:///c:/temp/root/79371609/925ee10/Autofac.DLL.
LOG: Attempting download of new URL file:///c:/temp/root/79371609/925ee10/Autofac/Autofac.DLL.
LOG: Attempting download of new URL file:///C:/Projects/Drive/temp/drive/Src/Web/bin/Autofac.DLL.
WRN: Comparing the Assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of Assembly (hr = 0x80131040). Probing terminated.

Stack Trace: 


[FileLoadException: Could not load file or Assembly 'Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The located Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)]
   Fairfax.Classifieds.Drive.Web.Global.RegisterTypesWithAutofac() in c:\Projects\Drive\temp\drive\Src\Web\Global.asax.cs:375
   Fairfax.Classifieds.Drive.Web.Global.Application_Start(Object sender, EventArgs e) in c:\Projects\Drive\temp\drive\Src\Web\Global.asax.cs:102

[HttpException (0x80004005): Could not load file or Assembly 'Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The located Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9936485
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Could not load file or Assembly 'Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The located Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9950728
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

更新:アセンブリリダイレクトバインディングもweb.configに追加しましたが、それでもエラーが発生しました。

<runtime>
        <assemblyBinding xmlns="urn:schemas-Microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="5.2.2.0" />
            </dependentAssembly>
    <dependentAssembly>
                <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" />
                <bindingRedirect oldVersion="1.0.0.0-3.4.0.0" newVersion="3.4.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

Autofac 3.3.0.0もGACに追加しようとしましたが、効果がありませんでした。

14
Jin Ho

おそらく、web.configにバインディングリダイレクトが必要です。バージョン3.5の場合、私のものは次のようになります。

  <dependentAssembly>
    <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
  </dependentAssembly>
20
Jim Bolla

古いXAMLビルドから新しいvNextビルドに移行した単体テストライブラリでこの問題が発生しました。 AutoFacを使用するすべてのライブラリに対してアセンブリバージョンバインディングリダイレクトを構成しました。私はまだ出力の問題で終わった。

最終的に、バインディングリダイレクト情報は、プロジェクトに対応するDLL)に対してのみ(binフォルダーに)出力され、含まれている他のすべてのDLLでは出力されないことがわかりました。ケースでは、AutoFacを必要とする別の(ユニットテスト)ライブラリへの参照がありました。このライブラリには、ビルドプロセスによっても検出され、実行時に失敗したユニットテストが含まれていました。問題は、参照で定義されたバインディングリダイレクトでした。参照されているライブラリの.configファイルがbinフォルダーに存在しなかったため、ライブラリは適用されていませんでした。

そこで、ユニットテストライブラリが他のユニットテストライブラリを参照しないようにすることで、これを解決しました。回避策として、共通コードプロジェクト、または共通コード用の共通C#プロジェクトライブラリを使用します。

AutoFacにアセンブリバインディングが必要な理由に関する追加情報がここにあります: すべてのAutofacパッケージが最新のAutofacコアをターゲットにしないのはなぜですか?

0
CJBS

ソリューションに<role name>.dll.configファイルを追加し(web.configまたはapp.configと同じレベル)、[出力ディレクトリにコピー]プロパティを[常にコピー]に設定する必要があります。このファイルには、bindingRedirect設定が含まれている必要があります。同じエラーが発生しました: FileLoadException:WebRole(リサイクルインスタンス)でファイルまたはアセンブリを読み込めませんでした

詳細については、 「System.IO.FileLoadException:ファイルまたはアセンブリを読み込めませんでした」というエラーでリサイクルされるクラウドサービスロール

0
Artyom