5

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?

Community
  • 1
  • 1
  • 1
    When you're debugging, the Modules window will show which DLLs are loaded, perhaps some of those are missing from your deployment. That technique won't help though, if AForge needs some config files as well. You could try watching the filesystem, using [Process Monitor](https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx), just enable only filesystem activity, add some filter for your app (to cut down on the noise), then look for which files could not be found at the time of the error. – Chris O Dec 28 '16 at 19:26
  • @ChrisO Thanks! I just did that, and it shows my app is looking for the AForge.NET libraries in the GAC. So I guess I need to find a way to either add the libraries to the GAC, or make it so it looks for the libraries elsewhere. – Rodrigo Salgado Atala Dec 28 '16 at 19:39

3 Answers3

8

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).

  • For anyone else, who like i did somehow, thinks that dll-files with the similar names but different versions e.g avcode-59.dll, avdevice-59.dll would work just as well: they don't! Please use the exact same files listed here – dtwk2 Aug 08 '22 at 13:29
  • Here are solutions for automatically including the dlls in the bin folder https://stackoverflow.com/questions/18743907/visual-studio-how-to-copy-to-output-directory-without-copying-the-folder-stru – dtwk2 Aug 08 '22 at 13:30
2

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.

Zafer ATLI
  • 41
  • 2
1

Try building your project in x86 platform.