Question

I have build a program that will read some video and audio information of a mkv file using MediaInfo.dll.

The program is working perfect when running from source, with the dll placed in the bin folder.

Now i want to publish my app and be able to continue using it. The MediaInfo.dll library is no longer found. I tried placing it in C:\WIndows\ or in C:\Windows\system32 with no luck. If i run the setup (after publishing) the program is installed in the same location (i don't want this but this is another problem). I tried placing the dll into that folder too.

The code that is throwing me the error is :

try{
  Handle = MediaInfo_New();
}
catch (Exception ex){
                Handle = (IntPtr)0;
Console.Out.WriteLine(ex.ToString());
}

The error throw is System.BadImageFormatException or System.DllNotFoundException: Unable to load DLL 'MediaInfo.dll'.

Any idea on where to place the dll ?

Was it helpful?

Solution

You need to deploy the DLL to the same directory in which you copied the EXE.

You are having trouble with BadImageFormatException and not seeing c:\windows\system32 work because you are deploying your program on a machine that boots the 64-bit version of Windows. However, your program cannot run in 64-bit mode, you have dependency on 32-bit native code. You'll need to fix that by forcing your program to run in 32-bit mode. Right-click your EXE project, Properties, Build tab, change the Platform target setting to x86. Copying the DLL to the Windows directory is a really bad idea, but it is c:\windows\syswow64 on such a machine. Always favor local deployment, same directory as the EXE.

If you still have trouble with DllNotFoundException after this then the likely problem is that MediaInfo.dll itself has a dependency on another DLL. Which is pretty common, the DLL that stores the C runtime is a very common dependency. If you have no idea what DLL that might be then you can use SysInternals' ProcMon utility. You'll see the program searching for the DLL and not finding it.

OTHER TIPS

You can try one of the below-

1) Place the MediaInfo.dll in the same location as the executable. Make sure that your program is built for the right target platform. I have seen BadImageFormatException usually when the target platform and the binaries have mismatch in architecture (x86 v/s x64). Packaging dependencies usually takes care of this.

2) Register MediaInfo.dll in Global Assembly Cache of the target machine. This can be done via an installer or simply using gacutil.exe. This will make the dll visible to all assemblies on the target machine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top