简体   繁体   中英

Unable to load assembly with platform setting all win32 or x86

I'm writing a program which is using C# and C++ (C# calls C++). On the internet people say that there is a conflict with 64bit and 32bit assembly but I have set all the projects to either win32 or x86. See image below. 当前设置

I also tried to set the C# application to "any cpu" but that has the same result. See image below for the error that I receive. 错误信息

On HansPassant's recommendation I changed my C# settings to prefer 32-bit , this results is the same error. 在此处输入图片说明

Does anyone know a solution to my current issue?

You will first need to identify the x86 and x64 library locations:

x86path = (Path.GetDirectoryName(Assembly.GetAssembly(GetType()).CodeBase) + @"\x86\").Replace("file:\\", "");
x64path = (Path.GetDirectoryName(Assembly.GetAssembly(GetType()).CodeBase) + @"\x64\").Replace("file:\\", "");

Then to utilize the library you want and properly call it you will want to try the InteropDotNet package: https://github.com/AndreyAkinshin/InteropDotNet

Github: https://www.nuget.org/packages/InteropDotNet/

You may not want to use the entire package, but it has a nice feature that generates the code to call the native library.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM