c# 64 bit .net c++ dll reference problem
-
I wrote one .net c++ dll,and reference it in an c# winform program .Prompt the following error: title: BadImageFormatException was unhandled content: Could not load file or assembly “CppDll, Version=1.0.4798.31848, Culture=neutral, PublicKeyToken=null”or one of its dependencies. the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well. This is a very simple test example code: part dll code:
namespace CppDll {
public ref class Class1 { // TODO: Add your methods for this class here. };
}
part exe code:
public Form1()
{
CppDll.Class1 cls = new CppDll.Class1();
InitializeComponent();
} -
I wrote one .net c++ dll,and reference it in an c# winform program .Prompt the following error: title: BadImageFormatException was unhandled content: Could not load file or assembly “CppDll, Version=1.0.4798.31848, Culture=neutral, PublicKeyToken=null”or one of its dependencies. the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well. This is a very simple test example code: part dll code:
namespace CppDll {
public ref class Class1 { // TODO: Add your methods for this class here. };
}
part exe code:
public Form1()
{
CppDll.Class1 cls = new CppDll.Class1();
InitializeComponent();
}peter462 wrote:
the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well.
Where are you changing? In the C# project?
Best wishes, Navaneeth My blog
-
I wrote one .net c++ dll,and reference it in an c# winform program .Prompt the following error: title: BadImageFormatException was unhandled content: Could not load file or assembly “CppDll, Version=1.0.4798.31848, Culture=neutral, PublicKeyToken=null”or one of its dependencies. the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well. This is a very simple test example code: part dll code:
namespace CppDll {
public ref class Class1 { // TODO: Add your methods for this class here. };
}
part exe code:
public Form1()
{
CppDll.Class1 cls = new CppDll.Class1();
InitializeComponent();
}It doesn't work because you compiled your C++ .DLL as 32-bit. You cannot mix 32- and 64-bit code in the same process. Either recompile your .DLL as 64-bit or go into your C# project properties and target x86 (32-bit) to force your C# code to run as 32-bit only.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
I wrote one .net c++ dll,and reference it in an c# winform program .Prompt the following error: title: BadImageFormatException was unhandled content: Could not load file or assembly “CppDll, Version=1.0.4798.31848, Culture=neutral, PublicKeyToken=null”or one of its dependencies. the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well. This is a very simple test example code: part dll code:
namespace CppDll {
public ref class Class1 { // TODO: Add your methods for this class here. };
}
part exe code:
public Form1()
{
CppDll.Class1 cls = new CppDll.Class1();
InitializeComponent();
}