既存の MVC3 アプリに WebApi を追加しています。NuGet Web Api パッケージを追加し、新しい Unity.dll を取得した後、次の問題が発生しています。
どうやら別のアセンブリが Unity.dll を参照しているようです (100% 確実ではありませんが、EnterpriseLibrary.Common だと思います - 最新の EntLib に更新しましたが、まだエラーが発生しています)。
以下の assemblyBinding を web.config に追加しました。しかし、アセンブリ バインディングは機能せず、古い Microsoft.Practices.Unity.dll をまだ探しています。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity" PublicKeyToken="31bf3856ad364e35" Culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-2.0.414.0" newVersion="2.1.505.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.Unity.Configuration" PublicKeyToken="31bf3856ad364e35" Culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-2.0.414.0" newVersion="2.1.505.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
私が見ているエラーからのスタックトレースは次のとおりです。
System.IO.FileLoadException
Could not load file or assembly 'Microsoft.Practices.Unity, Version=1.2.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)</Message><StackTrace>
Server stack trace:
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at System.Web.Http.Dispatcher.DefaultHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)
at System.Web.Http.WebHost.WebHostHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)
at System.Web.Http.Dispatcher.HttpControllerTypeCache.InitializeCache()
at System.Lazy`1.CreateValue()
Exception rethrown at [0]:
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at System.Web.Http.Dispatcher.DefaultHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)
at System.Web.Http.WebHost.WebHostHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)
at System.Web.Http.Dispatcher.HttpControllerTypeCache.InitializeCache()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache()
at System.Lazy`1.CreateValue()
Exception rethrown at [1]:
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at System.Web.Http.Dispatcher.DefaultHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)
at System.Web.Http.WebHost.WebHostHttpControllerTypeResolver.GetControllerTypes(IAssembliesResolver assembliesResolver)
at System.Web.Http.Dispatcher.HttpControllerTypeCache.InitializeCache()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)</StackTrace></Exception>