无法加载文件或程序集 'AForge.Video.FFMPEG.dll' 或其依赖项之一

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

我正在使用 Visual Studio Community 2015 开发 .NET 应用程序,它使用了一些 AForge.NET 库。我将引用添加到我的项目中,当我调试应用程序时,库工作正常。但是,当我发布应用程序并将其安装在同一台计算机上时,只要我到达使用 AForge.NET 库的应用程序的一部分,应用程序就会崩溃并出现以下错误:

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)

我在网上搜索了此问题的解决方案,到目前为止 none 以下方法对我有用:

此外,我搜索了安装该应用程序的文件夹,我看到所有 DLL 文件都在那里,每个文件都在不同的文件夹中,还有一个包含每个 DLL 和其他文件的文件夹。

我对其他库(全局程序集缓存中的库)没有任何问题,例如 MySql.Data

根据 Chris O 的建议,我使用 Process Monitor 检查我的应用程序,它显示它正在 GAC 中寻找 AForge 库;因为我没有在那里添加它们,所以无法找到它们。

我需要做什么才能配置我的应用程序以便它可以从应用程序文件夹访问库而不是在 GAC 中查找它们?

必须将外部库复制到包含 AForge.Video 库的安装文件夹。

AForge.Video 库包含一些无法添加为引用的外部 DLL 文件。相反,必须将它们复制到项目的 bin 文件夹中。同样,在安装应用程序后,必须将它们复制到其他 DLL 文件所在的文件夹中。文件夹的确切名称各不相同,但就我而言,我必须将它们复制到以下目录:

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

需要复制的DLL文件有:

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

我在制作与新 Visual Studio 项目相同的应用程序后注意到了这一点,并且忘记在新项目中复制外部库,这导致了开发中的相同错误(我之前没有得到).

启动后在 app.config 上添加 useLegacyV2RuntimeActivationPolicy="true"

喜欢

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

并将 Externals\ffmpeg\bin 中的 AForge 外部 dll 复制到项目 bin\debug 文件夹。

尝试在 x86 平台上构建您的项目。