It seems like a duplicate question from the title, but let me clarify that I have already searched and followed different methods.
Basically I have to import a managed C++ dll
into a C#
project. I consulted some tutorials and finally created a managed C++ dll
. Now while importing the dll
I got the following error:
An attempt was made to load a program with an incorrect format
I found some solutions like this but these solutions could not help me . Before facing this error I had to consult this solution and then this one too.
Here's a screenshot of how I am trying to import the dll
:
Settings:
Code:
Someone please guide me about the right way to import the dll
in my project.
This C++ library is for certain architecture (x64 or x86). C# on the other hand is not(Any CPU), that is why this kind of error - C# most likely assumes You have a x64 unmanaged library. You should restrict the architecture in C# project to either of these (x64 or x86) so in both projects they are the same.
Should you not be copying the file as a pre-build step? Make sure it is in the correct location before the build. I would also remove the exit 0
, it's not needed.
That DllImport
is usual for native C-style APIs, not the managed and C++/CLI assemblies. These .Net assemblies, be they mixed mode or not, can be added in the usual assembly dependency locations.
If this is a "Managed C++" and not a "C++/CLI" assembly, it may also be incompatible with the target .Net framework.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.