This project has moved and is read-only. For the latest updates, please go here.

1.3 version support for Vista 64 bit

Apr 6, 2011 at 3:44 PM

Hi there, I had 1.2 version of naudio working in my vista 64 bit machine. Was having issues using waveout.stop(). Browsing thr the discussion board, assumed this was resolved in 1.3 version.

Got 1.3 now, but this is what I see at runtime, not even able to run sample demo project.

{"Could not load file or assembly 'NAudio, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format."}


Apr 6, 2011 at 3:45 PM

you need to set the main executable to target x86


Apr 6, 2011 at 4:06 PM

Thanks much Mark for quick response. I tried with the sample code and it worked.

But again in my project, its still the same issue. Please help.

Apr 6, 2011 at 4:12 PM

have you set the target in your project?

Apr 6, 2011 at 5:14 PM

Thanks Mark, changing the traget to x86 works now. But still I see the same issue as in 1.2 with the waveout.stop().

if (this.waveOut != null && this.waveOut.PlaybackState != PlaybackState

.Stopped) {



ContextSwtichDeadlock error

The CLR has been unable to transition from COM context 0x74bed0 to COM context 0x74c040 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

Apr 6, 2011 at 5:18 PM

what sort of application are you running (WinFroms, WPF, something else)? in what what way are you using COM? What callback mechanism are you using for WPF?


Apr 6, 2011 at 5:36 PM

Its a Winforms app, .net 3.5. not a WPF. This is what we are doing, suspecting something wrong with the flow of events.

  public void PlaySoundFile(string fileName)
            FileStream stream = new FileStream(fileName, FileMode.Open);

 public void PlaySoundFile(Stream soundStream)
            // Create object
            this.waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());

            // Set volume
            if (this.playbackVolume != -1F)
                this.waveOut.Volume = this.playbackVolume;

            waveStream = new WaveFileReader(soundStream);
            waveChannel = new WaveChannel32(waveStream);
            this.waveOut.PlaybackStopped += new EventHandler(waveOut_PlaybackStopped);

            bool foundDevice = false;
            // Attempt to set correct device
            for (int i = 0; i < WaveOut.DeviceCount; i++)
                if (WaveOut.GetCapabilities(i).ProductName.Contains(Settings.Default.AudioPlaybackDevice))
                    // Set the device to playback audio on
                    waveOut.DeviceNumber = i;
                    foundDevice = true;

            // Make sure we find the audio device
            if (!foundDevice)
                throw new AudioDeviceNotFoundException(Settings.Default.AudioPlaybackDevice);



     public void StopPlayback()
            if (this.waveOut != null
                && this.waveOut.PlaybackState != PlaybackState.Stopped)
                    if (waveStream != null)
                        // this one really closes the file and ACM conversion
                        waveChannel = null;
                        // this one does the metering stream
                        waveStream = null;

                    waveOut = null;



Apr 6, 2011 at 5:40 PM

Try using Window callbacks. Also, in your StopPlayback function, don't dispose of WaveOut yet - it's not necesarily finished doing stuff. Finally, what are you doing in waveOut_PlaybackStopped?

Apr 6, 2011 at 6:54 PM
Edited Apr 6, 2011 at 6:55 PM


What do you mean by window callbacks? On paybackstopped, we are cleaning up the wave out object.


void waveOut_PlaybackStopped(object sender, EventArgs e)


// Clean-up the wave out object

if (this.waveOut != null)



this.waveOut = null;







Apr 8, 2011 at 6:47 AM

You are probably debugging in Visual studio?

see this post for a more deeply explanation:

I have had this several times when dealing with Directx, just configure VS not to react on this.

Apr 9, 2011 at 8:17 AM

try using WaveCallbackInfo.NewWindow() instead of function callbacks. Also, PlaybackStopped can be a dangerous place to call WaveOut.Dispose(), especially when using function callbacks.