我有一個案例,2個C#項目需要相互引用。因此,程序集A引用程序集B並且程序集B使用反射來加載A.在命令行應用程序中很好地工作。無法加載我正在執行的程序集
,但在我的Word 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
@阿魯納 - 對不起,我應該在一開始就這樣做。現在在那裏。 –
你的程序集(A和B)是如何部署的 - 就像它們應該駐留在文件系統中的位置一樣?你是否傳遞LoadFile方法的完整路徑? – cynic