Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / August 2007

Tip: Looking for answers? Try searching our database.

incorrect assembly format combined c++ c# on vista64

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SGRing - 24 Aug 2007 20:58 GMT
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.

Is there a way to fix this?
Willy Denoyette [MVP] - 24 Aug 2007 21:07 GMT
>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++
[quoted text clipped - 8 lines]
>
> Is there a way to fix this?

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

Willy.
SGRing - 24 Aug 2007 22:38 GMT
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.

> >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++
[quoted text clipped - 13 lines]
>
> Willy.
Willy Denoyette [MVP] - 24 Aug 2007 22:51 GMT
> 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.

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.
SGRing - 24 Aug 2007 23:42 GMT
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

> > 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
[quoted text clipped - 5 lines]
>
> Willy.
Willy Denoyette [MVP] - 25 Aug 2007 16:44 GMT
> 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.

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!

> 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
[quoted text clipped - 95 lines]
> A first chance exception of type 'System.TypeInitializationException'
> occurred in testcSharp.exe

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'
> occurred in testcSharp.exe

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.
SGRing - 27 Aug 2007 23:36 GMT
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.

> > 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.
[quoted text clipped - 116 lines]
>
> Willy.
SGRing - 28 Aug 2007 21:32 GMT
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.

> 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
[quoted text clipped - 165 lines]
> >
> > Willy.
Willy Denoyette [MVP] - 28 Aug 2007 23:08 GMT
> 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?

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.
SGRing - 28 Aug 2007 23:54 GMT
Thanks, that fixed it.

> > Here's the same result from the c++ program. The difference is that the
> > c++
[quoted text clipped - 7 lines]
>
> Willy.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.