1

新しい MVC 4 Web サイトを作成しています。Unity.MVC3 ライブラリを使用して、MVC に組み込まれている DependencyResolver と統合したいと考えています。

また、以前のはるかに大規模なプロジェクトからいくつかのデータ アクセス DLL を参照したいと考えています。

私の問題は、Unity.MVC3 と古い DLL がそれぞれ異なるバージョンの Unity 1.2.0.0 と 2.1.505.0 に対してコンパイルされていることです。次のように、web.config ファイルにバインディング リダイレクトを作成してみました。

  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersions="1.2.0.0-2.1.505.0" newVersion="2.1.505.0" />
  </dependentAssembly>

ただし、まだ次のエラーが表示されます。

 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)

アセンブリ バインディングのログ記録をオンにすると、最後の 2 行で次のように表示されます。

 WRN: Comparing the assembly name resulted in the mismatch: Major Version
 ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

バインディング リダイレクトが尊重されないのはなぜですか? メジャー バージョンの競合のチェックを無効にする方法はありますか?

4

1 に答える 1

2

キー トークンにタイプミスがあります。

<assemblyIdentity name="Microsoft.Practices.Unity" 
     publicKeyToken="31bf856ad364e35" />

次のようにする必要があります。

<assemblyIdentity name="Microsoft.Practices.Unity" 
     publicKeyToken="31bf3856ad364e35" />

Binding redirectは、タイプミスの場合に文句を言わず、何もしません。

テストアプリケーションを作成しましたが、この構成で動作します:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.2.0.0" newVersion="2.1.505.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

に注意しxmlnsてください。それがないと、黙って失敗します。

于 2012-09-10T06:52:10.383 に答える