故障排除:通过 Word 代码隐藏调用自定义代码时找不到引用的非托管 dll

发布于 2024-07-10 11:13:19 字数 3079 浏览 4 评论 0原文

上下文:

  1. 我有一个 WPF 应用程序,它使用 D:\WordAutomation\MyApp_Source\Executables\MyApp 文件夹中的某些非托管 DLL。 我可以双击该 exe 文件,一切都会运行。
  2. 接下来,我有一个 Word 2007 代码隐藏项目,它引用上述文件夹中的相关托管 DLL,并尝试执行相同的操作......调出应用程序 UI。 经过充分的“砍伐”后,我的用户界面显示出来。 但现在有一个用户操作强制加载非托管 dll 之一,该 dll 与 FileNotFoundException 一致地爆炸(没有帮助/指示缺少哪个文件)

我在问题行上放置了一个断点,清除了输出窗口,按 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 添加到与(word doc+VSTO)同一文件夹 dll)
  • 将该文件夹添加到PATH环境变量。 还是一样。
  • 我能想到的任何事情..在过去的几天里,

我注意到Word似乎正在将托管引用程序集复制到如下代码片段所示的位置..这可能是一系列调查。 但为什么 word 会这样做以及它如何解析非托管 DLL.. 我不知道。 同样在第一个片段中,有一些从 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.

终于优雅地结束了……救命!!

Context:

  1. I have a WPF App that uses certain unmanaged DLLs in the D:\WordAutomation\MyApp_Source\Executables\MyApp folder. I can double click the exe and everything runs.
  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. After adequate 'macheting', I get my UI to show up. 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)

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)

Case 1: Double-click on EXE.. which works perfectly (slightly snipped)

'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

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)
  • added the folder to the PATH Environment variable. 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. But why is word doing this and how does it resolve unmanaged DLLs.. I don't know. Also in the first snippet, there are some DLLs loaded from a WinSXS path, that could also be another lead.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

地狱即天堂 2024-07-17 11:13:19

要找出导致问题的 dll 以及在何处查找 dll,请使用 ProcessMon(来自 sysinternals)。

在这里查看我的回答:
参考答案

To find out what dll is causing the problem and where the dll is being looked for use ProcessMon (free from sysinternals).

See my answer here:
Referenced answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文