简体   繁体   中英

Load Unmanaged dll reference in ASP.NET MVC Core 1.0 (Aka) ASP.net 5 MVC 6

This question relates to an ASP.NET MVC WEP API, and Naudio

what I want

I was working prototype in WPF appliations when I use this code the wav file is converted to mp3

var retMs = new MemoryStream();
using (var ms = new MemoryStream(File.ReadAllBytes("sound.wav")))
using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(retMs, rdr.WaveFormat, 128))
{
    rdr.CopyTo(wtr);
}
return retMs.ToArray();

But when using this code in api project I am getting error like this

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

I know libmp3lame is unmanged dll, the WPF project I just copy the dll to bin folder and everything works fine, but how can I achieve this in Web API project, I mean asp.net 5 project

Note
the above code is working expected in wpf project

Also now I am only supported in my API is dotnetframwork means windows only I removed other platform dependencies

Update:

Created Issue in ASP.Net MVC Repo

I'm a little late to the party but I'll share this for posterity. NAudio can convert a WAVE to an MP3 without the unmanaged DLL to avoid this issue all together. The only snag is it has to write out to a file (which can then be read back in). Assuming you have a MemoryStream where you read all the bytes in (like you did):

using (var wfr = new WaveFileReader(ms))
{
    MediaFoundationApi.Startup();
    MediaFoundationEncoder.EncodeToMp3(wfr, @"C:\Temp\test.mp3", 48000);
    MediaFoundationApi.Shutdown();
}

Sounds like an issue with getting the mapping to the module in the bin library path, check out the following as may help -

How to get bin folder in ASP.NET Core 1.0

MVC4 App "Unable to load DLL 'libmp3lame.32.dll'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM