I'm developing an application (C# winforms) that relies upon a vendor-supplied DLL which communicates with hardware.
If I choose a target framework of .NET 4 (or anything higher), I get the following message when attempting to call a method in the referenced DLL:
DllNotFoundException: Unable to load DLL 'somelibrary.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)
If I choose a target framework of .NET 2.0 or 3.0, the error does not occur.
I suspect there is an incompatibility or that the library is older than .NET 3.0.
It is likely due to the fact the .DLL launches an executable which acts as a communications handler between the application and a serial port. I have tried setting that application to use various compatibility modes, and to run as administrator, without success.
What can I do to avoid this error and target a more modern .NET platform such as 4.5 or later? (Or am I necessarily stuck due to using a potentially rather old DLL?)
The application platform target is x86 and I am developing on Win7 x64 with UAC on default settings.
I don't say this is 100% correct solution but here is the idea, I believe valid.
This error usually happens when you have missing dependency. In your case dependency for your
somelibrary.dll. In FW2.0 most files were stored in some
Program files (x86)\Reference Assemblies.... We know that some things changed in FW4+ and some classes were moved, and assemblies no longer in
Program Files but downloaded via Nuget. So, what [most likely] happens, when you target FW4.0+, your app start to look for dependencies for v4.0. I would use some disassembler like free
dotPeek, to look what references you have inside the DLL in question. And then I would try to find these on the machine and see if you don't have version conflicts related to namespaces
User contributions licensed under CC BY-SA 3.0