疑难解答:在通过Word代码隐藏调用自定义代码时找不到引用的非托管dll

时间:2008-11-26 07:20:23

标签: .net ms-word vsto office-2007 assembly-resolution

背景:

  1. 我有一个WPF应用程序,它使用D:\ WordAutomation \ MyApp_Source \ Executables \ MyApp文件夹中的某些非托管DLL。我可以双击exe,一切都运行。
  2. 接下来,我有一个Word 2007代码隐藏项目,该项目引用上述文件夹中的相关托管DLL并尝试执行相同的操作。启动App UI。经过足够的'macheting',我得到我的UI出现。但现在有一个用户操作强制加载其中一个与FileNotFoundException一致的非托管dll(没有帮助/指示缺少哪个文件)
  3. 我在问题行上放置了断点,清除了输出窗口,按F10,比较了我运行该行时的输出(将对象添加到ObservableCollection,其CollectionChanged处理程序具有加载非托管块的代码)

    案例1:双击EXE ..完美运行(略微剪断)

    'MyApp.DesktopApp.exe': Loaded 'D:\WordAutomation\MyApp_Source\Executables\MyApp\ManagedFrameworkWrapper.dll', Symbols loaded.
    'MyApp.DesktopApp.exe': Loaded 'D:\WordAutomation\MyApp_Source\Executables\MyApp\Unmanaged.Framework.dll'
    'MyApp.DesktopApp.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcr90d.dll', Symbols loaded.
    'MyApp.DesktopApp.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcp90d.dll', Symbols loaded.
    'MyApp.DesktopApp.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugMFC_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_2a62a75b\mfc90ud.dll', Symbols loaded.
    'MyApp.DesktopApp.exe': Loaded 'C:\WINDOWS\system32\msimg32.dll'
    'MyApp.DesktopApp.exe': Loaded 'D:\WordAutomation\MyApp_Source\Executables\MyApp\HelperFunctions.dll'
    'MyApp.DesktopApp.exe': Loaded 'C:\WINDOWS\system32\dbghelp.dll'
    'MyApp.DesktopApp.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcm90d.dll', Symbols loaded.
    'MyApp.DesktopApp.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.MFCLOC_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_11f3ea3a\mfc90enu.dll', Binary was not built with debug information.
    CCollectionDataType ConstCCollectionDataType ConstCCollectionDataType ConstCCollectionDataType ConstCCollectionDataType ConstCCollectionDataType Const'MyApp.DesktopApp.exe' (Managed): Loaded 'D:\WordAutomation\MyApp_Source\Executables\MyApp\ManagedFrameworkWrapper.dll', Symbols loaded.
    'MyApp.DesktopApp.exe' (Managed): Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcm90d.dll', Symbols loaded.
    The thread 'Win32 Thread' (0x12ec) has exited with code 0 (0x0).
    

    案例2:运行相同的行,但是从Word代码隐藏的.cs文件中启动

    A first chance exception of type 'System.IO.FileNotFoundException' occurred in WindowsBase.dll
    The program '[5320] WINWORD.EXE: Managed' has exited with code 0 (0x0).
    

    我试过了

    • 将非托管DLL添加到与相同文件夹
    • 将文件夹添加到 PATH环境变量。还是一样。
    • 过去几天我能想到的任何事情

    我注意到Word似乎正在将托管引用程序集复制到一个位置,如下面的代码段所示..这可能是一个调查线。但为什么这样做是这样的,它如何解决非托管DLL ..我不知道。同样在第一个片段中,有一些DLL从WinSXS路径加载,也可能是另一个领导。

    'WINWORD.EXE' (Managed): Loaded 'C:\Documents and Settings\pillaigi\Local Settings\Application Data\assembly\dl3\6HQYB5GK.LY0\KC4WN109.HT4\4d81c901\70abeb86_124ec901\MyWPFPlotPopup.DLL', Symbols loaded.
    

    最后优雅地关闭......帮助!!

1 个答案:

答案 0 :(得分:1)

要找出导致问题的dll以及查找dll的位置,请使用ProcessMon(不含sysinternals)。

请在此处查看我的回答: Referenced answer