2012-07-19 105 views
-1

我正在爲應用程序編寫加載程序。 外接程序是一個DLL,它位於特定文件夾%APPDATA & /應用/加載項/ MyAddIn加載程序集的問題

所以,我有幾個項目的解決方案和MyAddInFolder包含下列文件:

IVC.Common.dll 
IVC.MaterialCatalogEditorAddIn.dll 
IVC.MaterialCatalogEditor.dll 

的位於所述IVC.MaterialCatalogEditorAddIn.dllIVC.MaterialCatalogEditorAddIn.dll應用程序調用方法參照的IVC.MaterialCatalogEditor.dllIVC.MaterialCatalogEdit or.dll引用到IVC.Common.dll

有一個WPF在IVC.MaterialCatalogEditor.dll 320交織。而就在XAML文件中被引用到IVC.Common.dll

當我嘗試從應用程序我得到一個異常執行外接程序指令「無法加載組件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. 

這裏一切就OK了。該IVC.MaterialCatalogEditorAddIn.dll電話* IVC.MaterialCatalogEditor.dll *在外接程序文件夾

但接下來的日誌:

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從測試可執行應用程序的一切工作正常。

EDITED 某些代碼:

的主要代碼在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

debbuger顯示錯誤o n在IVC.MaterialCatalogEditor中的這部分xaml。DLL

<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> 

組織編寫 我已經寫了具有相同結構的測試解決方案作爲我工作的解決方案。 從測試應用程序啓動它時,它沒有任何錯誤。但是,如果我從外接程序執行它,它失敗,「無法加載組件Common.dll」

Test Solution

+2

你能顯示任何相關的代碼嗎?你所提供的全部是應用程序特定的日誌。 – 2012-07-19 04:25:18

+0

增加了一些代碼 – 2012-07-19 04:44:50

+0

歡迎使用程序集加載地獄。安裝到GAC可能是唯一的解決方案。對於所有工作來說,第二個「日誌」仍然應該處於「加載」的上下文中。您可以嘗試預加載您的相關程序集,但不知道這是否可行。我看到了與VS插件相同的問題。 – leppie 2012-07-19 05:28:02

回答

1

雖然集探測失敗,你有一對夫婦的路要走:

  1. 更換組件使用app.config文件綁定
  2. 手柄組件 通過附加到當前應用程序的AssemblyResolve 域加載失敗並使用c#代碼加載必需的程序集。