x86 控制台应用程序在 64 位机器上不 运行 除了在调试器中

x86 console application doesn't run on 64bit machines except in debugger

为了更好地把握我的问题,我试图通过摆脱 NUnit 来降低复杂性。现在我编写了一个普通的控制台应用程序 (C#),它与 ​​c++/cli 包装器交互,后者调用公司框架 c++ dll。

Dumpbin 表示所有程序集都是 32 位的。 Visual Studio 已将控制台应用程序和包装器设置为 x86。在 x86 机器上控制台应用程序就像一个魅力,在 x64 上它没有,除非从我的 Visual Studio 2013 调用并附加调试器(当 运行 来自 Visual Studio 没有调试器)。程序集设置为 "Systemeigenes Codedebugging aktivieren"(激活本机?代码调试)并且 Visual Studio 托管进程已停用。 "It doesn't work" 表示为这样的东西:

 SetUp : System.IO.FileLoadException : Could not load file or assembly 'The_Wrapper.DLL' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)

我尝试在 64 位机器上使用 dependency walker(x86 版本)进行分析,但它在加载 IMM32.DLL 后死掉了。 x86机器上的输出是这样的:

 Operating System: Microsoft Windows NT/2000/XP/2003/Vista based Media Center (32-bit), version 6.01.7601 Service Pack 1
 Program Executable: d:\tmp\binplain\bin\PLAINCONSOLEAPPLICATION.EXE
 Program Arguments: 
 Starting Directory: D:\tmp\binplain\bin\
 Search Path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\

 Options Selected:
      Simulate ShellExecute by inserting any App Paths directories into the PATH environment variable.
      Log thread information.
      Use simple thread numbers instead of actual thread IDs.
      Log first chance exceptions.
      Log debug output messages.
      Use full paths when logging file names.
      Log a time stamp with each line of log.
      Automatically open and profile child processes.
 --------------------------------------------------------------------------------

 00:00:00.000: Started "d:\tmp\binplain\bin\PLAINCONSOLEAPPLICATION.EXE" (process 0x9F0) at address 0x01360000 by thread 1.
 00:00:00.000: Loaded "c:\windows\system32\NTDLL.DLL" at address 0x76F20000 by thread 1.
 00:00:00.000: Loaded "c:\windows\system32\MSCOREE.DLL" at address 0x6CB30000 by thread 1.
 00:00:00.015: Loaded "c:\windows\system32\KERNEL32.DLL" at address 0x75E00000 by thread 1.
 00:00:00.015: Loaded "c:\windows\system32\KERNELBASE.DLL" at address 0x75320000 by thread 1.
 00:00:00.046: Entrypoint reached. All implicit modules have been loaded.
 00:00:00.046: Loaded "c:\windows\system32\ADVAPI32.DLL" at address 0x77060000 by thread 1.
 00:00:00.046: Loaded "c:\windows\system32\MSVCRT.DLL" at address 0x76E70000 by thread 1.
 00:00:00.046: Loaded "c:\windows\system32\SECHOST.DLL" at address 0x76CA0000 by thread 1.
 00:00:00.062: Loaded "c:\windows\system32\RPCRT4.DLL" at address 0x75B30000 by thread 1.
 00:00:00.062: Loaded "c:\windows\microsoft.net\framework\v4.0.30319\MSCOREEI.DLL" at address 0x6C9E0000 by thread 1.
 00:00:00.062: Loaded "c:\windows\system32\SHLWAPI.DLL" at address 0x75DA0000 by thread 1.
 00:00:00.062: Loaded "c:\windows\system32\GDI32.DLL" at address 0x77100000 by thread 1.
 00:00:00.062: Loaded "c:\windows\system32\USER32.DLL" at address 0x75F70000 by thread 1.
 00:00:00.078: Loaded "c:\windows\system32\LPK.DLL" at address 0x76040000 by thread 1.
 00:00:00.078: Loaded "c:\windows\system32\USP10.DLL" at address 0x75A90000 by thread 1.
 00:00:00.078: Loaded "c:\windows\system32\IMM32.DLL" at address 0x75BE0000 by thread 1.
 00:00:00.078: Loaded "c:\windows\system32\MSCTF.DLL" at address 0x75CA0000 by thread 1.
 00:00:00.093: Loaded "c:\windows\microsoft.net\framework\v4.0.30319\CLR.DLL" at address 0x6B660000 by thread 1.
 00:00:00.093: Loaded "c:\windows\system32\MSVCR100_CLR0400.DLL" at address 0x6BCD0000 by thread 1.
 00:00:00.093: First chance exception 0x04242420 (Unknown) occurred in "c:\windows\system32\KERNELBASE.DLL" at address 0x7532B760 by thread 1.
 00:00:00.093: Thread 2 started in "c:\windows\microsoft.net\framework\v4.0.30319\CLR.DLL" at address 0x6B7C741C.
 00:00:00.093: Thread 3 started in "c:\windows\microsoft.net\framework\v4.0.30319\CLR.DLL" at address 0x6B7159C0.
 00:00:00.093: Thread 4 started in "c:\windows\system32\NTDLL.DLL" at address 0x76F4FD0F.
 00:00:00.093: Loaded "c:\windows\assembly\nativeimages_v4.0.30319_32\mscorlib\cece9d0256e18427b64587ba690605d4\MSCORLIB.NI.DLL" at address 0x6A890000 by thread 1.
 00:00:00.109: Loaded "c:\windows\microsoft.net\framework\v4.0.30319\NLSSORTING.DLL" at address 0x6BF70000 by thread 1.
 00:00:00.109: Loaded "c:\windows\system32\OLE32.DLL" at address 0x75930000 by thread 1.
 00:00:00.109: Loaded "c:\windows\system32\CRYPTBASE.DLL" at address 0x74FF0000 by thread 1.
 00:00:00.109: Loaded "c:\windows\microsoft.net\framework\v4.0.30319\CLRJIT.DLL" at address 0x6BF10000 by thread 1.
 00:00:00.124: Loaded "" at address 0x6BEB0000 by thread 1.
 00:00:00.124: Loaded "" at address 0x00640000 by thread 1.
 00:00:00.124: Unloaded "" at address 0x6BEB0000 by thread 1.
 00:00:00.124: Loaded "d:\tmp\binplain\bin\THE_WRAPPER.DLL" at address 0x6BEB0000 by thread 1.
 00:00:00.124: Loaded "d:\tmp\binplain\bin\CORE_QUANTITY_1_0.DLL" at address 0x6BE30000 by thread 1.
 00:00:00.140: Loaded "d:\tmp\binplain\bin\CORE_DATATYPES_1_0.DLL" at address 0x6BD90000 by thread 1.
 00:00:00.140: Loaded "d:\tmp\binplain\bin\CORE_MEMORY_1_0.DLL" at address 0x6A880000 by thread 1.
 00:00:00.140: Loaded "d:\tmp\binplain\bin\CORE_EXCEPTION_1_0.DLL" at address 0x6A870000 by thread 1.
 00:00:00.140: Loaded "c:\windows\system32\MSVCP120.DLL" at address 0x6A7F0000 by thread 1.
 00:00:00.140: Loaded "c:\windows\system32\MSVCR120.DLL" at address 0x6A700000 by thread 1.
 00:00:00.156: Loaded "d:\tmp\binplain\bin\OPENCV_CORE248.DLL" at address 0x6A4F0000 by thread 1.
 00:00:00.156: Loaded "d:\tmp\binplain\bin\DEVICECOM_CAMERA_IRSOFT_1_0.DLL" at address 0x6A4C0000 by thread 1.
 00:00:00.156: Loaded "d:\tmp\binplain\bin\DEVICECOM_STACK_1_0.DLL" at address 0x6A4B0000 by thread 1.
 00:00:00.156: Loaded "d:\tmp\binplain\bin\DEVICECOM_DEVICEHANDLER_CAMERA_1_0.DLL" at address 0x6A490000 by thread 1.
 00:00:00.156: Loaded "d:\tmp\binplain\bin\DEVICECOM_CAMERA_1_0.DLL" at address 0x6A3F0000 by thread 1.
 00:00:00.171: Loaded "d:\tmp\binplain\bin\DEVICECOM_CORE_1_0.DLL" at address 0x6A3B0000 by thread 1.
 00:00:00.171: Loaded "d:\tmp\binplain\bin\CORE_ACTION_1_0.DLL" at address 0x6A380000 by thread 1.
 00:00:00.171: Loaded "d:\tmp\binplain\bin\CORE_PROTOCOL_1_0.DLL" at address 0x6A360000 by thread 1.
 00:00:00.171: Loaded "d:\tmp\binplain\bin\CORE_SOCKET_1_0.DLL" at address 0x69DB0000 by thread 1.
 00:00:00.187: Loaded "c:\windows\system32\WS2_32.DLL" at address 0x75F30000 by thread 1.
 00:00:00.187: Loaded "c:\windows\system32\NSI.DLL" at address 0x76E60000 by thread 1.
 00:00:00.187: Loaded "c:\windows\system32\WINMM.DLL" at address 0x737A0000 by thread 1.
 00:00:00.187: Loaded "d:\tmp\binplain\bin\WDAPI1020.DLL" at address 0x10000000 by thread 1.
 00:00:00.187: Loaded "c:\windows\system32\OLEAUT32.DLL" at address 0x75C00000 by thread 1.
 00:00:00.202: Loaded "d:\tmp\binplain\bin\CORE_UTILS_1_0.DLL" at address 0x69D90000 by thread 1.
 00:00:00.202: Loaded "d:\tmp\binplain\bin\CORE_CODECS_1_0.DLL" at address 0x69D60000 by thread 1.
 00:00:00.202: Loaded "d:\tmp\binplain\bin\MEASUREMENTS_RADIOMETRY_1_0.DLL" at address 0x69DE0000 by thread 1.
 00:00:00.202: Loaded "d:\tmp\binplain\bin\VISION_IMGPROC_1_0.DLL" at address 0x69D30000 by thread 1.
 00:00:00.202: Loaded "d:\tmp\binplain\bin\CORE_IMGIO_1_0.DLL" at address 0x69860000 by thread 1.
 00:00:00.218: Loaded "d:\tmp\binplain\bin\OPENCV_HIGHGUI248.DLL" at address 0x697D0000 by thread 1.
 00:00:00.218: Loaded "c:\windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\COMCTL32.DLL" at address 0x6C5D0000 by thread 1.
 00:00:00.218: Loaded "c:\windows\system32\MSVFW32.DLL" at address 0x69D00000 by thread 1.
 00:00:00.218: Loaded "c:\windows\system32\SHELL32.DLL" at address 0x76050000 by thread 1.
 00:00:00.234: Loaded "c:\windows\system32\AVIFIL32.DLL" at address 0x697B0000 by thread 1.
 00:00:00.234: Loaded "c:\windows\system32\MSACM32.DLL" at address 0x72F70000 by thread 1.
 00:00:00.234: Loaded "c:\windows\system32\AVICAP32.DLL" at address 0x69790000 by thread 1.
 00:00:00.234: Loaded "c:\windows\system32\VERSION.DLL" at address 0x743B0000 by thread 1.
 00:00:00.234: Loaded "c:\windows\system32\VCOMP120.DLL" at address 0x69770000 by thread 1.
 00:00:00.249: Loaded "d:\tmp\binplain\bin\VISION_KEYDEFINITIONS_1_0.DLL" at address 0x69750000 by thread 1.
 00:00:00.249: Loaded "d:\tmp\binplain\bin\OPENCV_IMGPROC248.DLL" at address 0x694E0000 by thread 1.
 00:00:00.249: Loaded "d:\tmp\binplain\bin\VISION_RADIOMETRY_1_0.DLL" at address 0x69480000 by thread 1.
 00:00:00.249: Loaded "c:\windows\system32\IPHLPAPI.DLL" at address 0x732B0000 by thread 1.
 00:00:00.265: Loaded "c:\windows\system32\WINNSI.DLL" at address 0x73460000 by thread 1.
 00:00:00.265: Loaded "d:\tmp\binplain\bin\VISION_IMGIO_1_0.DLL" at address 0x69420000 by thread 1.
 00:00:00.265: Thread 5 started in "d:\tmp\binplain\bin\WDAPI1020.DLL" at address 0x10009168.
 00:00:00.265: Thread 6 started in "d:\tmp\binplain\bin\WDAPI1020.DLL" at address 0x10009168.
 00:00:00.265: Thread 7 started in "d:\tmp\binplain\bin\WDAPI1020.DLL" at address 0x10009168.
 00:00:00.280: Loaded "c:\windows\microsoft.net\framework\v4.0.30319\DIASYMREADER.DLL" at address 0x69370000 by thread 1.
 00:00:00.327: Loaded "c:\windows\system32\CRYPTSP.DLL" at address 0x74AF0000 by thread 1.
 00:00:00.343: Loaded "c:\windows\system32\RSAENH.DLL" at address 0x74890000 by thread 1.
 00:00:08.876: Thread 3 exited with code 0 (0x0).
 00:00:08.892: Thread 6 exited with code 0 (0x0).
 00:00:08.892: Thread 7 exited with code 0 (0x0).
 00:00:08.892: Thread 5 exited with code 0 (0x0).
 00:00:08.892: Thread 4 exited with code 0 (0x0).
 00:00:08.892: Thread 2 exited with code 0 (0x0).
 00:00:08.892: Exited "d:\tmp\binplain\bin\PLAINCONSOLEAPPLICATION.EXE" (process 0x9F0) with code 0 (0x0) by thread 1.

当我实际开发的软件产品(x86、C# WinForms)使用包装器时,即使没有调试器,它也能在 x64 上运行,但只能在我的开发 PC 上运行。

我忽略了什么?哪些工具可能对我有帮助?

有点尴尬,但还是会分享的:

我添加到这个现有项目中的公司框架库使用的是Jungo USB Driver。由于未知原因,文件 wdapi1020.dll 被签入并复制到我的 bin 目录中。不幸的是,它是该文件的 x86 版本。当我最终发现我必须删除它时,PlainConsoleApplication 使用了 SysWOW64 中的应用程序,一切顺利。现在我必须说服我们的管理员在构建服务器上安装驱动程序,或者说服框架开发人员改变他们对 Jungo 驱动程序的使用......它仍然很有趣。

对于感兴趣的人,以下是我的发现:我获取了问题末尾提到的软件产品并安装了它(而不是从 bin 文件夹中复制它)。当我将控制台应用程序放入它的文件夹时,它突然起作用了。我开始比较这些文件,发现实际上有一个太多了。删除后我的脸上露出了灿烂的笑容。