Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

asp.net mvc - MVC4 App "Unable to load DLL 'libmp3lame.32.dll'

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.

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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);
    }
}

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...