0

アプリケーションへのプラグインを開発しています。私のプラグインは WPF Toolkit 1.6.0.0 を使用しています。WPF Toolkit アセンブリには厳密な名前が付けられており、アセンブリへのすべての参照が特定のバージョンであることを確認しました。

ホスト アプリケーションは、以前のバージョンの WPF Toolkit (1.5.0.0) を使用します。プラグインが WPFToolkit をロードしようとすると、正しいアセンブリがプラグイン アセンブリと同じフォルダーにある場合でも、ホスト アプリケーションからバージョンがロードされます (このフォルダーから他の依存関係を問題なくロードします)。

ライブラリの正しいバージョンがロードされていることを確認するにはどうすればよいですか?

以下は、アセンブリ バインダーのログです。

*** Assembly Binder Log Entry  (29.11.2012 @ 09:35:17) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Path\To\Host\Application\Application.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = XXXXXXXXXXXXX
LOG: DisplayName = WPFToolkit.Extended, Version=1.6.0.0, Culture=neutral, PublicKeyToken=3e4669d2f30244f4
 (Fully-specified)
LOG: Appbase = file:///C:/Path/To/Host/Application/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = application.exe
Calling assembly : PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Path\To\Host\Application\petrel.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: WPFToolkit.Extended, Version=1.6.0.0, Culture=neutral, PublicKeyToken=3e4669d2f30244f4
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Path/To/Host/Application/WPFToolkit.Extended.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Path\To\Host\Application\WPFToolkit.Extended.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: WPFToolkit.Extended, Version=1.5.0.0, Culture=neutral, PublicKeyToken=3e4669d2f30244f4
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
4

1 に答える 1

0

この問題が発生した理由はまだわかりませんが、回避策を見つけました。アセンブリに接続してAppDomain.CurrentDomain.AssemblyResolve手動でロードすることで、アセンブリを正しくロードできました。

リゾルバーのコードは次のとおりです。

private static Assembly HandleAssemblyResolve(object sender, ResolveEventArgs args)
{
    Assembly requestingAssembly = (args.RequestingAssembly ?? Assembly.GetExecutingAssembly());
    AssemblyName assemblyName = new AssemblyName(args.Name);

    string currentLocation = requestingAssembly.Location;
    string baseDirectory = Path.GetDirectoryName(currentLocation);
    string assemblyLocation = Path.Combine(baseDirectory, assemblyName.Name + ".dll");

    if (File.Exists(assemblyLocation))
    {
        return Assembly.LoadFile(assemblyLocation);
    }

    return null;
}
于 2012-11-29T10:25:56.543 に答える