0

MEF、Webapi、および OData を使用する Web アプリがあります。MEF の場合、必要に応じてカタログをロードするヘルパー クラスを作成しました (最初のアクセス時)。

以下は、MEF 統合コードです。

Public Shared ReadOnly Property Catalog As AggregateCatalog
    Get
        If _catalog Is Nothing Then

            Dim catFolder = "."
            Dim path = AppDomain.CurrentDomain.BaseDirectory.ToLower
            _catalog = new AggregateCatalog()
            Dim di = New DirectoryInfo(path)
            Dim dlls = di.GetFileSystemInfos("MyApp.*.dll")
            _catalog = New AggregateCatalog()

            For Each dll In dlls
                Try
                    Dim ac = New AssemblyCatalog(Assembly.LoadFile(dll.FullName))
                    Dim parts = ac.Parts.ToArray() 'throws ReflectionTypeLoadException 
                    _catalog.Catalogs.Add(ac)

                Catch ex As ReflectionTypeLoadException
                    Log.Instance.Error("Error when Trying to load {0}", dll.FullName)
                    Log.Instance.Error(ex)
                    For Each iex In ex.LoaderExceptions
                        Log.Instance.Error(iex)
                    Next
                End Try
            Next
        End If
        Return _catalog
    End Get
End Property

私のプロジェクトの 1 つ (実際の Web アプリ プロジェクト) では、次の nuget パッケージを使用しています (特に): WebApi 5.2.3 WebApi.OData 5.7.0

私の問題は、MEF クラスがこのアセンブリを読み込もうとするときです (OData と WebApi を使用するアセンブリで、ランタイム エラーがスローされました。これは以下に記録されています。問題は、運用マシンでの展開でのみ発生します。開発ではすべて正常に動作します。

以下のエラーでわかるように、プロジェクトが System.Web.Http バージョン 5.2.3.0 を参照していても、実行時に System.Web.Http.Odata アセンブリが System.Web.Http バージョン5.2 を読み込もうとしているようです。 2.0 (!?!?!?)

私のプロジェクトでは、参照は正しい dll (バージョン 5.2.3.0) に設定され、dll はCopy Local=Trueで設定され、web.config には

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>

このプロジェクト (アセンブリ) には MEF で作成する必要のあるクラスがないため、MEF によるロードから単純に除外できますが、このエラーは私を困惑させ、解決策を見つけたいと考えています。他のアセンブリでも同様の問題が発生します。

ここに私が得るエラーがあります

2015-11-04 07:17:02.7758|ERROR|MyPermitNow.Log|Error when Trying to load m:\web\www.mypermitnow.org\web_1\bg-processor\MyPermitNow.Jurisdiction.dll
2015-11-04 07:17:02.7758|ERROR|MyPermitNow.Log|System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetEnumerator()
   at System.Linq.EnumerableQuery`1.GetEnumerator()
   at System.Linq.EnumerableQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at MyPermitNow.MEFHelper.get_Catalog()
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetEnumerator()
   at System.Linq.EnumerableQuery`1.GetEnumerator()
   at System.Linq.EnumerableQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at MyPermitNow.MEFHelper.get_Catalog()
2015-11-04 07:17:02.7758|ERROR|MyPermitNow.Log|System.IO.FileLoadException: Could not load file or assembly 'System.Web.Http, Version=5.2.2.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)
File name: 'System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

=== Pre-bind state information ===
LOG: DisplayName = System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///M:/web/www.mypermitnow.org/web_1/bg-processor/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Web.Http.OData, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///M:/web/www.mypermitnow.org/web_1/bg-processor/System.Web.Http.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
4

1 に答える 1