all groups > dotnet clr > august 2007 >
You're in the

dotnet clr

group:

incorrect assembly format combined c++ c# on vista64


incorrect assembly format combined c++ c# on vista64 SGRing
8/24/2007 12:58:02 PM
dotnet clr:
I have an x86 managed c++ dll. I can access it without problems from c++ or
c# on 32 bit platforms. On vista64, I can use it from a 32 c++ application.
But, on vista64, if I try to load it from a c# application (targeting either
the x86 or the x64 platform) I get "Could not load file or assembly or one of
its dependencies. An attempt was made to load a program with an incorrect
format". The managed c++ dll, accesses some unmanaged c++ dll's from a 3rd
party.

Re: incorrect assembly format combined c++ c# on vista64 SGRing
8/24/2007 2:38:01 PM
As far as I can tell, everything should be 32 bit. I set the properties of
the c# project to be x86 and it shows the 32 bit .net get loaded. But, I
still get the error.

[quoted text, click to view]
Re: incorrect assembly format combined c++ c# on vista64 SGRing
8/24/2007 3:42:04 PM
The managed c++ dll is linked with /MACHINE:X86, and it works fine on a 32
bit machine, and it works fine with a 32 bit c++ app.

I don't know if this will help. But here is the output of the loads.
Tester.exe is the c++ app, testcSharp is the c sharp app. They are both
trying to load the same crutilNet.dll

'tester.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'tester.exe' (Managed): Loaded 'c:\projects\crutilNet\debug\tester.exe',
Symbols loaded.
'tester.exe' (Managed): Loaded 'c:\projects\crutilNet\debug\msvcm80d.dll',
No symbols loaded.
'tester.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'tester.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'tester.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'tester.exe' (Managed): Loaded 'c:\projects\crutilNet\debug\crutilNet.dll',
Symbols loaded.
'tester.exe' (Managed): Loaded
'C:\Windows\WinSxS\x86_microsoft.vc80.debugcrt_1fc8b3b9a1e18e3b_8.0.50727.762_none_24c8a196583ff03b\msvcm80d.dll', Symbols loaded.



'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\projects\crutilNet\testcSharp\bin\Debug\testcSharp.vshost.exe', Skipped
loading symbols. Module is optimized and the debugger option 'Just My Code'
is enabled.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\System.Deployment\2.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
The thread 0x1188 has exited with code 0 (0x0).
The thread 0x158 has exited with code 0 (0x0).
The thread 0xa4 has exited with code 0 (0x0).
'testcSharp.vshost.exe' (Managed): Loaded
'C:\projects\crutilNet\testcSharp\bin\Debug\testcSharp.exe', Symbols loaded.
'testcSharp.vshost.exe' (Managed): Loaded
'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll',
Skipped loading symbols. Module is optimized and the debugger option 'Just My
Code' is enabled.
A first chance exception of type 'System.TypeInitializationException'
occurred in testcSharp.exe



[quoted text, click to view]
Re: incorrect assembly format combined c++ c# on vista64 Willy Denoyette [MVP]
8/24/2007 10:07:51 PM
[quoted text, click to view]



As the 3rd party dll is 32 bit all other assemblies (c# AND managed CO++)
need to be 32 bit as well.

Willy.
Re: incorrect assembly format combined c++ c# on vista64 Willy Denoyette [MVP]
8/24/2007 11:51:18 PM
[quoted text, click to view]

How about the managed C++ DLL, is it compiled as 32 bit (see linker option
/machine)?
There must be some component with incompatible bitness in the game.

Willy.



Re: incorrect assembly format combined c++ c# on vista64 Willy Denoyette [MVP]
8/25/2007 5:44:36 PM
[quoted text, click to view]

Is there a 64bit version of this module installed on this machine? If there
is none, then I don't see where the incorrect assembly comes from!

[quoted text, click to view]

I'm afraid this isn't of great help, all I can say is that you are running a
debug version from within VS, the debug version uses the VS hosting process
(I don't like that, so I always turn this off in my project settings). The
hosting process (and your testcSharp.exe) are clearly 32 bit as the loader
load the 32 bit version of System.Data (from the 32 bit GAC).
But where it fails isn't quite revealing, this:
A first chance exception of type 'System.TypeInitializationException'
[quoted text, click to view]
tells us that there is a "TypeInitializationException", but at this point
the managed module isn't loaded yet. I would suggest you to enable fusion
logging and have a look at the log.

Willy.
Re: incorrect assembly format combined c++ c# on vista64 SGRing
8/27/2007 3:36:01 PM
I've taken my 32 my installer, which installs a working project on all 32 bit
machines, and installed it on clean 64 bit machines (xp & vista). These are
machines that only have the os, and my application. In both cases I get
invalid format errors from my two dll's that are managed c++ dll's. Also in
both cases, I can load these dll's without error using a managed c++ main
program in place of my c# main program.

I have run fuslogvw (output below), but I don't see anything useful there.

*** Assembly Binder Log Entry (8/27/2007 @ 4:26:04 PM) ***

The operation failed.
Bind result: hr = 0x8007000b. An attempt was made to load a program with an
incorrect format.

Assembly manager loaded from:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable C:\Program Files (x86)\CRTech\Sinaps\Sinaps2.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = VMXP64\steve
LOG: DisplayName = crutilNet, Version=1.0.2734.19007, Culture=neutral,
PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/CRTech/Sinaps/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : Sinaps2Dll, Version=1.0.2791.27028, Culture=neutral,
PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files
(x86)/CRTech/Sinaps/crutilNet.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Program
Files (x86)\CRTech\Sinaps\crutilNet.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: crutilNet, Version=1.0.2734.19007, Culture=neutral,
PublicKeyToken=null
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing
terminated.


[quoted text, click to view]
Re: incorrect assembly format combined c++ c# on vista64 SGRing
8/28/2007 1:32:25 PM
Here's the same result from the c++ program. The difference is that the c++
main program load Framework, and the c# main program loads Framework64. So,
how can I get the c# program to just use Framework?


*** Assembly Binder Log Entry (8/28/2007 @ 2:27:37 PM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable C:\Program Files (x86)\CRTech\Sinaps\tester.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = VMXP64\steve
LOG: DisplayName = crutilNet, Version=1.0.2795.13312, Culture=neutral,
PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/CRTech/Sinaps/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : tester, Version=1.0.2795.13314, Culture=neutral,
PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files
(x86)/CRTech/Sinaps/crutilNet.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Program
Files (x86)\CRTech\Sinaps\crutilNet.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: crutilNet, Version=1.0.2734.19007, Culture=neutral,
PublicKeyToken=null
LOG: Binding succeeds. Returns assembly from C:\Program Files
(x86)\CRTech\Sinaps\crutilNet.dll.
LOG: Assembly is loaded in default load context.



[quoted text, click to view]
Re: incorrect assembly format combined c++ c# on vista64 SGRing
8/28/2007 3:54:02 PM
Thanks, that fixed it.

[quoted text, click to view]
Re: incorrect assembly format combined c++ c# on vista64 Willy Denoyette [MVP]
8/29/2007 12:08:05 AM
[quoted text, click to view]


If the C# main program loads the 64 bit framework it's because it's build
using the default platform flag value (MSIL). You need to build your C#
program with "platform = X86" in order to load the 32 bit framework.

Willy.
AddThis Social Bookmark Button