MVC4 应用程序“无法加载 DLL 'libmp3lame.32.dll'" [英] MVC4 App "Unable to load DLL 'libmp3lame.32.dll'

查看:23
本文介绍了MVC4 应用程序“无法加载 DLL 'libmp3lame.32.dll'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 MVC4 应用程序中使用 NAudio.Lame 库,但出现错误:

I am trying to use the NAudio.Lame library in an MVC4 application and am getting the error:

Unable to load DLL 'libmp3lame.32.dll': The specified module could not be found.

我通过 NuGet 添加了库.我能够使库与 Windows 窗体应用程序一起正常工作,因此我相信该问题特定于 MVC4.

I added the library via NuGet. I was able to get the library to work fine with a Windows Forms application, so I believe the problem is specific to MVC4.

我在这里尝试了图书馆作者的建议:https://stackoverflow.com/a/20065606/910348

I tried the advice from the library author here: https://stackoverflow.com/a/20065606/910348

推荐答案

问题出在本机 DLL(libmp3lame.32.dlllibmp3lame.64.dll) 无法找到,因为 Web 服务器进程正在执行的当前目录不是网站的 bin 文件夹(DLL 所在的位置)并且搜索路径不包括 bin 文件夹.

The problem turns out to be that the native DLLs (libmp3lame.32.dll and libmp3lame.64.dll) cannot be found because the current directory that the web server process is executing from is not the website's bin folder (where the DLLs reside) and the search path does not include the bin folder.

您需要的是将 bin 文件夹添加到 PATH 环境变量中,这将启用 LoadLibrary API 调用来定位 DLL.

What you need is to add the bin folder to the PATH environment variable, which will enable the LoadLibrary API call to locate the DLLs.

您可以调用以下方法来为您执行此操作:

Here's a method you can call that will do this for you:

public static void CheckAddBinPath()
{
    // find path to 'bin' folder
    var binPath = Path.Combine(new string[] { AppDomain.CurrentDomain.BaseDirectory, "bin" });
    // get current search path from environment
    var path = Environment.GetEnvironmentVariable("PATH") ?? "";

    // add 'bin' folder to search path if not already present
    if (!path.Split(Path.PathSeparator).Contains(binPath, StringComparer.CurrentCultureIgnoreCase))
    {
        path = string.Join(Path.PathSeparator.ToString(), new string[] { path, binPath });
        Environment.SetEnvironmentVariable("PATH", path);
    }
}

将它放在您的控制器中并在您创建 LameMP3FileWriter 实例之前调用它.如果您将它放在 Global.asax.cs 中并从 Application_Start() 调用它,它可能会起作用.试试看,让我知道它在那里是否有效.

Place that in your controller and call it right before you create the LameMP3FileWriter instance. It might work if you put it in Global.asax.cs and call it from Application_Start(). Try it and let me know if it works there.

我在项目网站上发布了一篇关于此的 Wiki 文章 此处.

I've put a Wiki article about this on the project site here.

这篇关于MVC4 应用程序“无法加载 DLL 'libmp3lame.32.dll'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆