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

2

In order to get a better hold on my question NUnit: Could not load file or assembly 'some.dll' or one of its dependencies. The specified module could not be found I tried to reduce complexity by getting rid of NUnit. Now I wrote a plain console application (C#) which interacts with a c++/cli wrapper which does calls on company framework c++ dlls.

Dumpbin says that all assemblies are 32bit. Visual Studio has console application and wrapper set to x86. On x86 machines console application works like a charm, on x64 it doesn't, except when being called from my Visual Studio 2013 with debugger attached (doesn't work when run from Visual Studio without debugger). The assembly is set to "Systemeigenes Codedebugging aktivieren" (activate native? code debugging) and Visual Studio hosting process is deactivated. "It doesn't work" is represented by something like this:

 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)

I tried profiling with dependency walker (x86 version) on the 64 bit machines, but it dies after loading IMM32.DLL. The output on a x86 machine is like this:

 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.

When the wrapper is used by the software product I am actually developing (x86, C# WinForms) it works on x64 even without debugger, but only on my development PC.

What am I overlooking? Which tools might help me?

c#
32bit-64bit
asked on Stack Overflow Jun 23, 2016 by Florian Straub • edited May 23, 2017 by Community

1 Answer

2

Am a little embarassed, but will share anyway:

The company framework library which I added to this existing project uses Jungo USB Driver. For unknown reasons the file wdapi1020.dll was checked in and copied to my bin directory. Unfortunately it was the x86 version of the file. When I finally figured out that I have to remove it, the PlainConsoleApplication used the one from SysWOW64 and everything went well. Now I have to convince either our admins to install the driver on the buildserver or the framework developers to change something about their usage of Jungo driver .... it will remain interesting.

For the ones interested, here's how I found out: I took the software product mentioned at the end of the question and installed it (instead of copying it from bin folder). When I put the console application into it's folder it suddenly worked. I started comparing the files and figured out that there is actually one too much. Removed it had a biiig smile on my face.

answered on Stack Overflow Jun 23, 2016 by Florian Straub

User contributions licensed under CC BY-SA 3.0