我正在为应用程序编写加载项。AddIn 是一个 Dll,它位于特定文件夹 %APPDATA&/Application/AddIns/MyAddIn
因此,我有一个包含多个项目的解决方案,并且 MyAddInFolder 包含以下文件:
IVC.Common.dll
IVC.MaterialCatalogEditorAddIn.dll
IVC.MaterialCatalogEditor.dll
应用程序调用位于IVC.MaterialCatalogEditorAddIn.dll和IVC.MaterialCatalogEditorAddIn.dll中的方法(引用IVC.MaterialCatalogEditor.dll和IVC.MaterialCatalogEditor.dll引用IVC.Common.dll)
IVC.MaterialCatalogEditor.dll中有一个 WPF froms 。并在 xaml 文件中引用了IVC.Common.dll
当我尝试从应用程序执行 AddIn 命令时,出现异常“无法加载程序集IVC.Common.dll ”
我使用了 FusionLogViewer,我得到了以下消息日志
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Program Files\Autodesk\Revit Structure 2012\Program\Revit.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = SK\ChekalinVV
LOG: DisplayName = IVC.MaterialCatalogEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Revit.exe
Calling assembly : IVC.MaterialCatalogEditorAddIn, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Program Files\Autodesk\Revit Structure 2012\Program\Revit.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: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/IVC.MaterialCatalogEditor.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/IVC.MaterialCatalogEditor/IVC.MaterialCatalogEditor.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/IVC.MaterialCatalogEditor.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/IVC.MaterialCatalogEditor/IVC.MaterialCatalogEditor.EXE.
LOG: Attempting download of new URL file:///C:/Users/ChekalinVV/AppData/Roaming/Autodesk/Revit/Addins/2012/IVC/FamilyManager/IVC.MaterialCatalogEditor.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Users\ChekalinVV\AppData\Roaming\Autodesk\Revit\Addins\2012\IVC\FamilyManager\IVC.MaterialCatalogEditor.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: IVC.MaterialCatalogEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
LOG: Where-ref bind Codebase does not match what is found in default context. Keep the result in LoadFrom context.
LOG: Binding succeeds. Returns assembly from C:\Users\ChekalinVV\AppData\Roaming\Autodesk\Revit\Addins\2012\IVC\FamilyManager\IVC.MaterialCatalogEditor.dll.
LOG: Assembly is loaded in LoadFrom load context.
这里一切正常。IVC.MaterialCatalogEditorAddIn.dll调用 * IVC.MaterialCatalogEditor.dll * 在 AddIn 文件夹中
但下一个日志:
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Program Files\Autodesk\Revit Structure 2012\Program\Revit.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = SK\ChekalinVV
LOG: DisplayName = IVC.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = Revit.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:\Program Files\Autodesk\Revit Structure 2012\Program\Revit.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: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/IVC.Common.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/IVC.Common/IVC.Common.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/IVC.Common.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Revit Structure 2012/Program/IVC.Common/IVC.Common.EXE.
LOG: All probing URLs attempted and failed.
PresebtationFramework 程序集尝试调用IVC.Common.dll并尝试仅从应用程序文件夹加载。
为什么一个 dll 尝试从 AddIn 文件夹加载,而另一个 dll 仅尝试从应用程序文件夹加载?以及如何解决我的问题。
所有项目都有任何 CPU 平台目标。该应用程序是 x64。
当我从测试可执行应用程序加载IVC.MaterialCatalogEditor.dll时,一切正常。
编辑了 一些代码:
IVC.MaterialCatalogEditorAddIn.dll中的主要代码
[Transaction(TransactionMode.ReadOnly)]
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
MaterialsWindow materialsWindow =
new MaterialsWindow();
materialsWindow.DataContext =
new MaterialsViewModel();
materialsWindow.ShowDialog();
return Result.Succeeded;
}
}
MaterialsWindow 类和 MaterialsViewModel 类位于IVC.MaterialCatalogEditor.dll
调试器在IVC.MaterialCatalogEditor.dll的这部分 xaml 上显示错误:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ViewModel="clr-namespace:IVC.MaterialCatalogEditor.ViewModel"
xmlns:Common="clr-namespace:IVC.Common;assembly=IVC.Common">
<DataTemplate
DataType="{x:Type Common:ResourceWithCharge}">
<!-- Some data template -->
</DataTemplate>
</ResourceDictionary>
EDITED 2 我已经编写了与我的工作解决方案具有相同结构的测试解决方案。当我从测试应用程序启动它时,它没有任何错误。但是,如果我从 AddIn 执行它,它会失败并显示“无法加载程序集 Common.dll”