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

System.FormatException occured in NAudio.dll

Dec 18, 2014 at 4:48 AM
So I've been working on a soundboard application for the past week, and I've pretty much gotten everything else in the application to work, except for that one error that I haven't been able to fix.

The error only occurs at runtime, and it doesn't crash the application, plus the audio file doesn't play, and I receive the error in console.

This is the part that attempts to play the file. I declared most if not all of the Naudio related things on the class level because I used them in other procedures.
 Private waveOut As New NAudio.Wave.WaveOut
 Dim intOutputDevices = waveOut.DeviceCount
 Dim deviceInfo As NAudio.Wave.WaveOutCapabilities

Private Sub playAudio(ByVal strFilePath As String, ByVal intDeviceNumber As Integer)

        Dim waveReader As New NAudio.Wave.WaveFileReader(strFilePath)
        waveOut.DeviceNumber = intDeviceNumber
        waveOut.Init(New NAudio.Wave.WaveChannel32(waveReader))

End Sub

Private Sub stopPlaying()
End Sub
This is where I called the method. I stored the file names in a dictionary with the keys of the dictionary being the literal key that I press on my keyboard to play the audio file, and the value being the file name. GetAsyncKeyState is the function that checks for keypresses.
 For Each pair In KeyBindings

            If (GetAsyncKeyState(pair.Key)) Then

                For intOutputDevice = 0 To intOutputDevices - 1

                    deviceInfo = NAudio.Wave.WaveOut.GetCapabilities(intOutputDevice)


                        If deviceInfo.ProductName.Contains(cboOutputDevice.SelectedItem) Then
                            playAudio(pair.Value, intOutputDevice)
                        End If

                    Catch ex As Exception

                        If cboOutputDevice.SelectedIndex = -1 Then
                            MsgBox("Please select an output device")
                        End If

                        If Not IO.File.Exists(pair.Value) Then
                            MsgBox("File does not exist.")
                        End If

                    End Try


            End If

Any help at all would be very much appreciated,

Thank you.
Dec 28, 2014 at 3:37 PM
can you provide the full exception.ToString, including stack trace?