简体   繁体   English

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

[英]Troubleshooting: Can't find a referenced unmanaged dll when invoking custom code via a Word code-behind

Context: 内容:

  1. I have a WPF App that uses certain unmanaged DLLs in the D:\\WordAutomation\\MyApp_Source\\Executables\\MyApp folder. 我有一个WPF应用程序,该应用程序在D:\\ WordAutomation \\ MyApp_Source \\ Executables \\ MyApp文件夹中使用某些非托管DLL。 I can double click the exe and everything runs. 我可以双击该exe,然后一切运行。
  2. Next I have a Word 2007 code-behind project, that references relevant managed DLLs in the above folder and tries to do the same thing.. bring up the App UI. 接下来,我有一个Word 2007代码隐藏项目,该项目引用上述文件夹中的相关托管DLL,并尝试执行相同操作。.调出App UI。 After adequate 'macheting', I get my UI to show up. 经过足够的“砍刀”后,我得到了我的UI。 But now there is a user-action that forces loading of one of the unmanaged dlls that blows up consistently with a FileNotFoundException (with no help/indication of which file is missing) 但是,现在有一个用户操作,该操作强制加载一个非托管的dll,并与FileNotFoundException一致地崩溃(没有帮助/缺少哪个文件的指示)

I have placed a breakpoint on the problem line, cleared output window, Press F10, compared the output when I run that line (adding an object to an ObservableCollection, whose CollectionChanged handler has code that loads up the unmanaged piece) 我在问题行上放置了一个断点,清除了输出窗口,按F10键,在运行该行时比较了输出(将对象添加到ObservableCollection中,该对象的CollectionChanged处理程序具有加载非托管代码的代码)

Case 1: Double-click on EXE.. which works perfectly (slightly snipped) 情况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).

Case 2: Run the same line, but launched from within a Word code-behind .cs file 情况2:运行同一行,但从.cs文件后面的Word代码中启动

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

I have tried 我努力了

  • adding the unmanaged DLLs to the same folder as the (word doc+VSTO dll) 将非托管DLL添加到 (word doc + VSTO dll) 相同的文件夹
  • added the folder to the PATH Environment variable . 将文件夹添加到PATH环境变量中 Still the same. 还是一样。
  • anything I could think of.. for the past couple of days 过去几天我能想到的任何事情

I notice that Word seems to be copying over the managed ref assemblies to a location as shown in below snippet.. which may be a line of investigation. 我注意到Word似乎正在通过托管引用程序集将其复制到以下代码段中所示的位置..这可能是调查的结果。 But why is word doing this and how does it resolve unmanaged DLLs.. I don't know. 但是,为什么要这么做呢?为什么要解析非托管的DLL ?。我不知道。 Also in the first snippet, there are some DLLs loaded from a WinSXS path, that could also be another lead. 同样在第一个片段中,从WinSXS路径中加载了一些DLL,这也可能是另一个线索。

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

Finally to close off gracefully... Help!! 终于优雅地关闭了...帮助!

To find out what dll is causing the problem and where the dll is being looked for use ProcessMon (free from sysinternals). 要找出导致问题的dll是什么,以及在哪里寻找dll,请使用ProcessMon(不包含sysinternals)。

See my answer here: Referenced answer 在这里查看我的答案: 参考答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM