2つのC#プロジェクトが互いに参照する必要があるケースがあります。したがって、アセンブリAはアセンブリBを参照します。アセンブリBはリフレクションを使用してAをロードします。コマンドラインアプリケーションでうまく動作します。実行中のアセンブリをロードできません
しかし、私の言葉COMアドインで、私は次のエラーを取得しています:
Could not load file or assembly 'WindwardReports, Version=15.0.142.0, Culture=neutral,
PublicKeyToken=34ffe15f4bbb8e53' or one of its dependencies.
The system cannot find the file specified.
FusionLog
=== Pre-bind state information ===
LOG: DisplayName = WindwardReports, Version=15.0.142.0, Culture=neutral, PublicKeyToken=34ffe15f4bbb8e53 (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/
LOG: Initial PrivatePath = NULL Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\\Program Files (x86)\\Microsoft Office\\Root\\Office16\\WINWORD.EXE.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\config\\machine.config.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/WindwardReports.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/WindwardReports/WindwardReports.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/WindwardReports.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Office/Root/Office16/WindwardReports/WindwardReports.EXE.
この同じコードは、コマンドラインのアプリで正常に動作します。
コード: ここにコードがあります。 (構文はちょっと変わっていますが、これはIKVMを使用して.NETに変換されるJavaコードですが、実行中は.NETコードです)。
cli.System.Reflection.Assembly assm;
int indexSemi = outputBuilder.indexOf(';');
if (indexSemi != -1) {
String dllFilename = outputBuilder.substring (0, indexSemi);
outputBuilder = outputBuilder.substring(indexSemi + 1);
assm = cli.System.Reflection.Assembly.LoadFile(dllFilename);
}
else
assm = cli.System.Reflection.Assembly.GetExecutingAssembly();
cli.System.Runtime.Remoting.ObjectHandle hdl = cli.System.Activator.CreateInstance(assm.get_FullName(), outputBuilder);
return (IOutputBuilderEngine) hdl.Unwrap();
System.Activator.CreateInstance()は例外をスローします。
コードを投稿できますか? – Aruna
@Aruna - 申し訳ありませんが、私は最初にそれをしていたはずです。今そこにいる。 –
あなたのアセンブリ(AとBの両方)はどのように配備されていますか?ファイルシステム内のどこに配置されていますか? LoadFileメソッドに完全なパスを渡していますか? – cynic