Using C++/CLR library with C# app

A

Andrew Jarvis

I have created from scratch...
a C++/CLR class library, CPlusPlusDLL, and added a single class Test with
nothing but a constructor and
a C# Windows Forms Application, CSharpApp, that creates an instance of Test
in the constructor of Form1.

When I run the app I get the message:

An unhandled exception of type 'System.BadImageFormatException' occurred in
CSharpApp.exe

Additional information: Could not load file or assembly 'CPlusPlusDLL,
Version=1.0.3274.27857, Culture=neutral, PublicKeyToken=null' or one of its
dependencies. An attempt was made to load a program with an incorrect
format.
___________________

I expected this to 'just work' and I don't know where to go from here.

Any ideas please?
 
A

Andrew Jarvis

I figured it out eventually.

I'm running under Windows XP x64. The DLL needs to be built for the x64
platform.
 
B

Ben Voigt [C++ MVP]

Andrew said:
I have created from scratch...
a C++/CLR class library, CPlusPlusDLL, and added a single class Test
with nothing but a constructor and
a C# Windows Forms Application, CSharpApp, that creates an instance
of Test in the constructor of Form1.

When I run the app I get the message:

An unhandled exception of type 'System.BadImageFormatException'
occurred in CSharpApp.exe

Additional information: Could not load file or assembly 'CPlusPlusDLL,
Version=1.0.3274.27857, Culture=neutral, PublicKeyToken=null' or one
of its dependencies. An attempt was made to load a program with an
incorrect format.
___________________

I expected this to 'just work' and I don't know where to go from here.

Any ideas please?

Most likely you compiled a 32-bit C++ DLL and left the C# setting on
automatic, then ran on 64-bit Windows. If you are using 32-bit DLLs you
should force the C# setting to x86 as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top