无法加载程序集或其依赖项

11

我正在使用Aforge.net框架进行图像处理工作。 我已经将'AForge.Video.FFMPEG.dll'添加为我的项目引用。 我正在使用VS2012和32位构建目标。 构建时出现以下错误:

 System.IO.FileNotFoundException was unhandled
  HResult=-2147024770
  Message=Could not load file or assembly 'AForge.Video.FFMPEG.dll' or one of its dependencies. The specified module could not be found.
  Source=VideoReadere
  FileName=AForge.Video.FFMPEG.dll
  FusionLog=""
  StackTrace:
       at VideoReadere.Form1..ctor()
       at VideoReadere.Program.Main() in c:\Users\Prabad\Documents\Visual Studio 2012\Projects\VideoReadere\VideoReadere\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

我的代码出现了异常

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VideoReadere
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
//here below line give exception
            Application.Run(new Form1());
        }
    }
}

1
AForge.Video.FFMPEG.dll 是否存在于可执行路径中? - Sriram Sakthivel
在VS的“引用”文件夹下,您是否看到了AForge.Video.FFMPEG.dll旁边的黄色三角形? - Arian Motamedi
如果您已经正确添加了引用,那么我会注意错误消息中的这一部分:“或其依赖项之一”。您是否还引用了 AForge.Video.FFMPEG.dll 所依赖的所有 DLL? - Ben Robinson
我如何找到AForge.Video.FFMPEG.dll的依赖项。 - Prathibha Chiranthana
使用 Dependancy Walker 工具来查找您的依赖项。您可以从 http://www.dependencywalker.com/ 下载该工具。 - Raghu
将"C:\Program Files (x86)\AForge.NET\Framework\Externals\ffmpeg\bin"中的DLL文件复制到您的Aforge.FFMPEG DLL路径中,然后解决混合模式错误。 - SaddamBinSyed
8个回答

11

你需要将来自“Externals\ffmpeg\bin”的DLL文件复制到AForge.Video.FFMPEG.dll的位置,也许还需要安装Microsoft Visual C++ Redistributable。


2
还需要在app.config中替换以下标签:<startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> <requiredRuntime version="v4.0.20506" /> </startup> - Keshan Fernando
短语“找不到指定的模块”意味着(在您的情况下)需要安装C++可再发行包。 - Igor S

3

虽然有点晚了,但我希望我的回答能帮到一些人。我遇到过这个问题,让我花费了一些时间。

  1. 项目 -> 添加现有项(浏览到“Externals\ffmpeg\bin”中提到的DLL文件,如其他答案所述)
  2. 确保您在文件类型下拉列表中显示所有类型
  3. 选择所有DLL文件,在添加按钮中选择添加链接选项
  4. DLL文件应该显示在您的项目解决方案中,选择它们所有
  5. 编辑Build Action属性并将其设置为NativeBinary
  6. 编辑Copy to Output Directory并将其设置为Copy Always

就是这样。 这对我有效,我发布了我的应用程序,并在Windows平板电脑上运行它。


我在第5步中没有找到“NativeBinary”选项。 - Leonel Sanches da Silva

2

请尝试以下方法:

检查项目目标是否为x86,因为汇编文件在64位上无法运行。然后检查FFMPEG动态链接库是否位于您应用程序的相同目录下。


0

我通过在发布模式下重新构建项目来解决问题(我使用的是Visual Studio 2013)


0

试试这个工具:Dependency Walker。它曾经帮我节省了不少时间。

编辑: 抱歉,我太晚看到最后一条评论了。


0
为了解决这个错误,我将目标 CPU 更改为 X86,以与被引用的 Chilkat-dll 组件的架构相匹配。对于其他 dll,您必须选择与 dll 组件架构匹配的项目正确的目标 CPU。错误将被解决。右键单击项目名称 > 属性 > 编译 > 目标 CPU --> 您将进入目标 CPU。

0

我尝试了所有推荐的解决方案,但都没有起作用。当我使用DependencyWalker时,我注意到该库缺少文件(版本2.2.5)。因此,我下载了之前的版本2.2.4,现在它对我来说运行良好。


0
这对我有用:
  1. App.Config中添加useLegacyV2RuntimeActivationPolicy="true"
  2. 链接两个dll - AForge.Video.dllAForge.Video.FFMPEG.dll
  3. \AForge.NET Framework-2.2.5\Externals\ffmpeg\bin *.dlls复制到输出文件夹中

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接