I built a C# application with WPF on Visual Studio 2012 that uses C++ DLL and targets .NET4.5. I have two projects running, one for the C# project and the other for C++ DLL project. I released both projects into a folder that has a .exe
for C# and a .dll
for C++ in the same folder.
I run them on my machine where they were developed and everything works fine. I run the .exe
in other machines and it throws this exception:
System.DllNotFoundException: Unable to load DLL
It's not recognizing the DLL that is in the same folder.
I tried many things and nothing seems to work. I followed the solution in this post but nothing worked.
The Dev and Target machine are identical. In Dev, Visual Studio 2012 is installed, but that's the only difference.
[DllImport(@"Wireless.dll", EntryPoint = "?cert_exists@certificate@CertFuncs@@SAHHPBD@Z", CallingConvention = CallingConvention.Cdecl)]
static extern int cert_exists(int store, [MarshalAs(UnmanagedType.LPTStr)]string cert_str);
static int __declspec(dllexport) cert_exists(int type, LPCSTR cert_str);
If I install Visual Studio 2012 on the target machine, everything works fine. If I remove it, the application crashes again. Any ideas on what VS is adding that can make the application work?
Just a guess: install Microsoft Visual C++ 2012 Redistributable Package on the user's machine. The native DLL you use may have other dependencies which have to be installed (try Dependency Walker). If the native DLL requires for example registry settings, config files etc. these should also be present. It should be distributed to user machines the same way you installed it on the dev machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With