简体   繁体   English

在ASP.NET MVC Core 1.0(Aka)ASP.net 5 MVC 6中加载非托管dll参考

[英]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 此问题与ASP.NET MVC WEP API和Naudio有关

what I want 我想要的是

I was working prototype in WPF appliations when I use this code the wav file is converted to mp3 当我使用此代码时,我正在WPF应用程序中使用原型,wav文件转换为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 但是在api项目中使用此代码时,出现了这样的错误

Unable to load DLL 'libmp3lame.dll': The specified module could not be found. 无法加载DLL'libmp3lame.dll':找不到指定的模块。

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 我知道libmp3lame是未管理的dll,在WPF项目中,我只是将dll复制到bin文件夹,并且一切正常,但是如何在Web API项目中实现这一目标,我的意思是asp.net 5项目

Note 注意
the above code is working expected in wpf project 上面的代码在wpf项目中正常工作

Also now I am only supported in my API is dotnetframwork means windows only I removed other platform dependencies 另外现在我的API仅支持dotnetframwork,这意味着只有Windows 删除了其他平台依赖项

Update: 更新:

Created Issue in ASP.Net MVC Repo 在ASP.Net MVC创建问题回购

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. NAudio可以将WAVE转换为MP3,而无需使用非托管DLL,从而避免了这个问题。 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): 假设您有一个MemoryStream,在其中读取了所有字节(就像您一样):

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 - 在bin库路径中获取到模块的映射听起来像是一个问题,请查看以下内容,可能会有所帮助-

How to get bin folder in ASP.NET Core 1.0 如何在ASP.NET Core 1.0中获取bin文件夹

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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