MVC4应用程序“无法加载DLL”libmp3lame.32.dll' [英] MVC4 App "Unable to load 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 Forms应用程序使图书馆工作正常,所以我相信这个问题是针对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.dll
和 libmp3lame.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.
我在项目网站 here 。
这篇关于MVC4应用程序“无法加载DLL”libmp3lame.32.dll'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!