Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'AForge.Video.FFMPEG.dll' or one of its dependencies

I'm developing a .NET app using Visual Studio Community 2015, which uses some of the AForge.NET libraries. I added the references to my project, and when I debug the app the libraries work fine. However, when I publish the app and install it in the same computer, as soon as I reach a part of the application in which the AForge.NET libraries are used, the app crashes with the following error:

System.IO.FileNotFoundException: Could not load file or assembly 'AForge.Video.FFMPEG.dll' or one of its dependencies. The specified module could not be found.
Filename: 'AForge.Video.FFMPEG.dll'
    on MyApp.mySecondForm..ctor(Int32 id)
    on MyApp.myMainForm.myListView_DoubleClick(Object sender, EventArgs e)
    on System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
    on System.Windows.Forms.ListView.WndProc(Message& m)
    on System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    on System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    on System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I've searched online for solutions to this, and so far none of the following has worked for me:

  • Installing Visual Studio C++ Redistributable (thinking it might have been a missing dependency)
  • Using the File System Editor to add the library on installation (I can't find the editor in Visual Studio).

Also, I searched for the folder where the app was installed, and I see all the DLL files are there, each in a different folder, along with a single folder with every DLL among other files.

I have no issues with other libraries (the ones in the Global Assembly Cache), such as MySql.Data.

Following a suggestion by Chris O, I used the Process Monitor to check on my app, and it shows it's looking for the AForge libraries in the GAC; since I haven't added them there, there's no way they can be found.

What do I need to do in order to configure my app so it can access the libraries from an app folder instead of looking for them in the GAC?

like image 555
Rodrigo Salgado Atala Avatar asked Dec 23 '22 22:12

Rodrigo Salgado Atala


2 Answers

External libraries must be copied to the installation folder that contains the AForge.Video libraries.

The AForge.Video library includes a few external DLL files that cannot be added as references. Instead, they must be copied to the bin folder of the project. Likewise, after installing the app, they must be copied to the folder where the other DLL files reside. The exact name of the folder varies, but in my case, I had to copy them to the following directory:

C:\Users\ User Name \AppData\Local\Apps\2.0\3V9YACJD.EPJ\V4BGBR0L.485\appe..tion_0000000000000000_0001.0008_b483b48e9712fa89

The DLL files that need to be copied are:

  • avcodec-53.dll
  • avdevice-53.dll
  • avfilter-2.dll
  • avformat-53.dll
  • avutil-51.dll
  • postproc-52.dll
  • swresample-0.dll
  • swscale-2.dll

I noticed this after making the same app as a new Visual Studio project, and forgetting to copy the external libraries in the new project, which caused the same error in development (which I didn't get before).

like image 109
Rodrigo Salgado Atala Avatar answered Apr 07 '23 11:04

Rodrigo Salgado Atala


add useLegacyV2RuntimeActivationPolicy="true" on app.config after startup

like

`<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>`

and copy AForge external dll in Externals\ffmpeg\bin to project bin\debug folder.

like image 32
Zafer ATLI Avatar answered Apr 07 '23 13:04

Zafer ATLI