統合テストを実行していて、そのコード行に到達すると:
WebApiDependencyResolverConfig.Register(config);
(内部で autofac コンテナを使用)
私はこの例外を受け取ります:
{"Could not load file or assembly 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"}
融合ログ:
=== Pre-bind state information ===
LOG: DisplayName = System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/TLP/TLP.API.IntegrationTests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : Autofac.Integration.WebApi, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\TLP\TLP.API.IntegrationTests\bin\Debug\TLP.API.IntegrationTests.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config
autofac Web API 統合は、Web API 2.0 までしか機能しないようです。system.web.http 5.0.0 を参照せず、代わりに 5.1.0 を参照する Web API 2.1 を使用すると、動作しなくなります。
5.0.0 ではなく system.web.http 5.1.0 バージョンを使用するように autofac に指示するにはどうすればよいですか?
これを統合テスト AND API プロジェクトの app.config に入れました。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Http"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<bindingRedirect oldVersion="5.0.0.0"
newVersion="5.1.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
しかし、うまくいきませんでした!
非常に奇妙なもう 1 つのことは、.NET 4.5.1 を使用すると、このリダイレクト アセンブリが自動的に行われることを読んだことです。しかし、それは起こっていません...