The request is invalid because Shutdown() has been called. (Exception from HRESULT: 0xC00D3E85)


Overview

NAudio has long provided a the .Net community with a robust library to handle audio processing. One of the features that I used recently was the ability to convert a WAVE file into an MP3 without any external libraries provided outside of the NAdudio distribution (like lame). On my first pass I encountered the following error:

System.Runtime.InteropServices.COMException: 'The request is invalid because Shutdown() has been called. (Exception from HRESULT: 0xC00D3E85)'

In order to fix this error I updated my code to call both MediaFoundationApi.Startup() and MediaFoundationApi.Shutdown(). Provided below is a snippet of code to accomplish writing a file out. Make an assumption that the "ms" variable is a MemoryStream that has been populated with the bytes of a WAVE file you've read in.

C#

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

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.

b
b - Monday, June 20, 2022

Thanks, exactly what I was looking for...