Python Ctypes – loading dll throws OSError: [WinError 193] %1 is not a valid Win32 application

Mentioning [Python.Docs]: ctypes – A foreign function library for Python (although this doesn’t have very much to do with it) just in case. The underlying error is ERROR_BAD_EXE_FORMAT (193, 0xC1). Check it in [MS.Docs]: System Error Codes (0-499). It’s a general Win error (not related to Python). In the current case (related to Python), the … Read more

java.lang.UnsatisfiedLinkError no *****.dll in java.library.path

In order for System.loadLibrary() to work, the library (on Windows, a DLL) must be in a directory somewhere on your PATH or on a path listed in the java.library.path system property (so you can launch Java like java -Djava.library.path=/path/to/dir). Additionally, for loadLibrary(), you specify the base name of the library, without the .dll at the … Read more

Dynamically load a function from a DLL

LoadLibrary does not do what you think it does. It loads the DLL into the memory of the current process, but it does not magically import functions defined in it! This wouldn’t be possible, as function calls are resolved by the linker at compile time while LoadLibrary is called at runtime (remember that C++ is … Read more

Loading DLLs at runtime in C#

Members must be resolvable at compile time to be called directly from C#. Otherwise you must use reflection or dynamic objects. Reflection namespace ConsoleApplication1 { using System; using System.Reflection; class Program { static void Main(string[] args) { var DLL = Assembly.LoadFile(@”C:\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\DLL.dll”); foreach(Type type in DLL.GetExportedTypes()) { var c = Activator.CreateInstance(type); type.InvokeMember(“Output”, BindingFlags.InvokeMethod, null, … Read more

System.MissingMethodException: Method not found?

This is a problem which can occur when there is an old version of a DLL still lingering somewhere around. Make sure that the latest assemblies are deployed and no duplicated older assemblies are hiding in certain folders. Your best bet would be to delete every built item and rebuild/redeploy the entire solution.