c# - x86 控制台应用程序不能在 64 位计算机上运行(调试器除外)

标签 c# 32bit-64bit

为了更好地理解我的问题NUnit: Could not load file or assembly 'some.dll' or one of its dependencies. The specified module could not be found我试图通过摆脱 NUnit 来降低复杂性。现在,我编写了一个普通控制台应用程序 (C#),它与 ​​c++/cli 包装器交互,该包装器调用公司框架 c++ dll。

Dumpbin 表示所有程序集都是 32 位的。 Visual Studio 将控制台应用程序和包装器设置为 x86。在 x86 机器上,控制台应用程序就像一个魅力,在 x64 上却不然,除非从附加了调试器的 Visual Studio 2013 调用(从没有调试器的 Visual Studio 运行时不起作用)。程序集设置为“Systemeigenes Codedebugging aktivieren”(激活 native ?代码调试),并且 Visual Studio 托管进程被停用。 “它不起作用”可以用这样的方式表示:

 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 驱动程序。由于未知原因,文件 wdapi1020.dll 被 checkin 并复制到我的 bin 目录。不幸的是,这是该文件的 x86 版本。当我最终发现必须删除它时,PlainConsoleApplication 使用了 SysWOW64 中的一个,一切都很顺利。现在我必须说服我们的管理员在构建服务器上安装驱动程序,或者说服框架开发人员更改他们对 Jungo 驱动程序的使用......这仍然很有趣。

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

关于c# - x86 控制台应用程序不能在 64 位计算机上运行(调试器除外),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37986855/

相关文章:

java - 将 Eclipse Luna 项目从 32 位迁移到 64 位时出现问题

c# - 应用程序资源与静态变量

c# - 匹配所有有效格式 IPv6 地址的正则表达式

c# - 在 Visual Studio 中查找命名空间的引用

c# - 将 List<string> 绑定(bind)到组合框

c++ - Windows:构建同一 DLL 的 32 位和 64 位版本

c# - ASP.NET Identity UserManager IIdentityMessageService 将额外参数传递给 SendAsync

c - 老师提供的 x86_64 库与我的系统不兼容

C++ 64 位时间戳到 32 位 time_t

ruby exec powershell 窗口