Answered by:
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll

Question
-
I am programming in Visual Basic 2008, and I recorded a sound with "Adobe Sound Booth CS3", Sound Fordge, and Windows Sound Recorder Test.WAV or Test.MP3, and then imported it into my Resources in Visual Basic 2008. But every time I try to drag and drop it into the Audio section in the resources it places itself into files catagory, and the icon looks like it has no program associated with it. I have written this line of code several times before and have never had this problem with this.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
My.Computer.Audio.Play(My.Resources.Test, AudioPlayMode.Background)
End Sub
End Class
It gives me this error...
The wave header is corrupt.
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
Like it said, I've did programs using this line of code before, and even my other EXE programs run fine, I can even use an old sound file, and it works, but why not now...?
It runs in the back of my mind that I read somewhere that Microsoft can make changes to the Visual Basic 2008 Express Eddition without notifing the users of the IDE.
So what do I need to do...? This is really depressing, I am good at programming, but am still learning, and I really don't have all the answers all the time, thats probably why I'm new here.
I tried to ask this question in Yahoo Answers, but they seem to not be smart enough to answer my question properly... I haven't got no answers there, lets see if MSDN Forums can answer this question, I hope they can, Can You...?
Tuesday, February 3, 2009 5:44 PM
Answers
-
Hi,
Following on from Programble suggestion just make sure that your not dragging an mp3 in and then playing it as a wav. It seems like such a silly suggestion "I not that stupid" but it's maybe just something that daft. If you do this sort of thing all the time then sometime you can have a head slap moment.
If that wasn't the problem then maybe the wave file has been corrupted. Try another wav file.
Also add a breakpoint to the line...
My.Computer.Audio.Play(My.Resources.Test, AudioPlayMode.Background)
And hold your mouse over My.Resources.Test and make sure it is the right type for the Play() method.
Does your computer play the WAV file ok?
Last suggestion is if you can upload a small project somewhere and let us download it. Thing is we could try it out on a new project and it all works perfectly. We could download the problem project and then that works then the problem might lie with your machine. Just difficult without more information.
www.dsmyth.net | www.dsmyth.net/wiki- Proposed as answer by Stuck on Code Thursday, February 5, 2009 4:09 AM
- Marked as answer by Martin Xie - MSFT Tuesday, February 10, 2009 3:02 AM
Wednesday, February 4, 2009 10:53 PM -
I just tested it by adding a .mp3 file to my projects resources, renamed it Test, and Ran this code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click My.Computer.Audio.Play(My.Resources.Test, AudioPlayMode.Background) End Sub End Class
I get the exact same error you get when trying to play the file. i.e.: "The wave header is corrupt." Noticed I used a .mp3 file.
Next I tried a .wav file, and it worked fine. The reason is because like Programble said...... My.Computer.Audio.Play uses .wav files! Not .mp3 files!
Finally to prove it for sure, instead of using My.Resources, I pointed the .Play method directly to .mp3 file on my harddrive, and ran it again. This time I get the error:
"The file located at C:\Users\me\Music\New Folder\Some.mp3 is not a valid wave file." See the end of the error message..... "NOT A VALID WAVE FILE"
It even tells you right here, that its for playing wave files: http://msdn.microsoft.com/en-us/library/cf1shcah.aspx
Furthermore. These files sitting in your project resources. If you look at them do they have the media player icon, or is it just a generic icon. If its a .wav file it will have the media player icon.
Compensating what I don't know yet, with what I do know now.- Proposed as answer by Stuck on Code Thursday, February 5, 2009 4:09 AM
- Marked as answer by Martin Xie - MSFT Tuesday, February 10, 2009 2:59 AM
Thursday, February 5, 2009 4:08 AM -
Do this. Right click your toolbox, and click on choose items. Click on the COM tab, and scroll down. Select the Windows Media Player. Now you have the real windows media player at your disposal with all the codecs you have installed.
Drag and drop the control on your form. Set its visible property to false, then you can do this:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AxWindowsMediaPlayer1.URL = "C:\Users\me\Music\New Folder\adf.mp3" End Sub
Compensating what I don't know yet, with what I do know now.- Proposed as answer by Stuck on Code Thursday, February 5, 2009 4:17 AM
- Edited by Stuck on Code Thursday, February 5, 2009 4:32 AM added code sample
- Marked as answer by Martin Xie - MSFT Tuesday, February 10, 2009 3:00 AM
Thursday, February 5, 2009 4:16 AM
All replies
-
Is your audio file playable from Windows Media Player? Which is it, test.wav, or test.mp3? My.Computer.Audio cannot play MP3 files.
Hobby programmer in VB, C#, HTML, CSS, PHP, JS, C++
http://www.programble.co.cc/
http://programble.blogspot.com/
programble@programble.co.cc- Proposed as answer by Stuck on Code Thursday, February 5, 2009 4:09 AM
- Unproposed as answer by Martin Xie - MSFT Tuesday, February 10, 2009 3:00 AM
Tuesday, February 3, 2009 9:07 PM -
Why, would that matter...?
If I type the code, it should compile and not have to give it a second thought.
Why now...?
I did my computer over, wiped everything, today, the Testing.wav file shows up in audio section in resources, and shows its a valid WAV file and stays in the audio section in resources, but it still gives the message...
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.InvalidOperationException: The wave header is corrupt.
at System.Media.SoundPlayer.ValidateSoundData(Byte[] data)
at System.Media.SoundPlayer.LoadAndPlay(Int32 flags)
at System.Media.SoundPlayer.Play()
at Microsoft.VisualBasic.Devices.Audio.Play(SoundPlayer sound, AudioPlayMode mode)
at Microsoft.VisualBasic.Devices.Audio.Play(Stream stream, AudioPlayMode playMode)
at AceClassifiedApplication.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\Administrator\AppData\Local\Temporary Projects\AceClassifiedApplication\Form1.vb:line 4
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3074 (QFE.050727-3000)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
AceClassifiedApplication
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/Administrator/Documents/Visual%20Studio%202008/Projects/AceClassifiedApplication/AceClassifiedApplication/bin/Release/AceClassifiedApplication.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
What do I need to do in order to get back to work...?
Thanx so much for replying, here's the total error report, ...
Wednesday, February 4, 2009 10:31 PM -
Hi,
Following on from Programble suggestion just make sure that your not dragging an mp3 in and then playing it as a wav. It seems like such a silly suggestion "I not that stupid" but it's maybe just something that daft. If you do this sort of thing all the time then sometime you can have a head slap moment.
If that wasn't the problem then maybe the wave file has been corrupted. Try another wav file.
Also add a breakpoint to the line...
My.Computer.Audio.Play(My.Resources.Test, AudioPlayMode.Background)
And hold your mouse over My.Resources.Test and make sure it is the right type for the Play() method.
Does your computer play the WAV file ok?
Last suggestion is if you can upload a small project somewhere and let us download it. Thing is we could try it out on a new project and it all works perfectly. We could download the problem project and then that works then the problem might lie with your machine. Just difficult without more information.
www.dsmyth.net | www.dsmyth.net/wiki- Proposed as answer by Stuck on Code Thursday, February 5, 2009 4:09 AM
- Marked as answer by Martin Xie - MSFT Tuesday, February 10, 2009 3:02 AM
Wednesday, February 4, 2009 10:53 PM -
I tried importing images and such on here, as examples, but, how would I go about uploading the exe or the project...?
It's strange, because older previously made WAV files, worked, and even MP3's worked as well, I don't understand why it gives this new error message, when I know before I could write this line of code, and it would run 100%, no problems, now even the audio file, "wav" file shows up in the audio section in resources, and vb2008 reconizes that its a "wav" file, ... yeah, I can play anything on here, but when it gets time to execute this command with the "wav" file in the resources it gives the error, Currupt wav header...
IDK...
I can't seem to figure this out, maybe re-download the Visual Studio 2008, and start over...?
But I don't see how that would change anything, since I'm running it right now...
. . .Thursday, February 5, 2009 3:35 AM -
I just tested it by adding a .mp3 file to my projects resources, renamed it Test, and Ran this code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click My.Computer.Audio.Play(My.Resources.Test, AudioPlayMode.Background) End Sub End Class
I get the exact same error you get when trying to play the file. i.e.: "The wave header is corrupt." Noticed I used a .mp3 file.
Next I tried a .wav file, and it worked fine. The reason is because like Programble said...... My.Computer.Audio.Play uses .wav files! Not .mp3 files!
Finally to prove it for sure, instead of using My.Resources, I pointed the .Play method directly to .mp3 file on my harddrive, and ran it again. This time I get the error:
"The file located at C:\Users\me\Music\New Folder\Some.mp3 is not a valid wave file." See the end of the error message..... "NOT A VALID WAVE FILE"
It even tells you right here, that its for playing wave files: http://msdn.microsoft.com/en-us/library/cf1shcah.aspx
Furthermore. These files sitting in your project resources. If you look at them do they have the media player icon, or is it just a generic icon. If its a .wav file it will have the media player icon.
Compensating what I don't know yet, with what I do know now.- Proposed as answer by Stuck on Code Thursday, February 5, 2009 4:09 AM
- Marked as answer by Martin Xie - MSFT Tuesday, February 10, 2009 2:59 AM
Thursday, February 5, 2009 4:08 AM -
Do this. Right click your toolbox, and click on choose items. Click on the COM tab, and scroll down. Select the Windows Media Player. Now you have the real windows media player at your disposal with all the codecs you have installed.
Drag and drop the control on your form. Set its visible property to false, then you can do this:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AxWindowsMediaPlayer1.URL = "C:\Users\me\Music\New Folder\adf.mp3" End Sub
Compensating what I don't know yet, with what I do know now.- Proposed as answer by Stuck on Code Thursday, February 5, 2009 4:17 AM
- Edited by Stuck on Code Thursday, February 5, 2009 4:32 AM added code sample
- Marked as answer by Martin Xie - MSFT Tuesday, February 10, 2009 3:00 AM
Thursday, February 5, 2009 4:16 AM -
Is it maybe an mp3 file that has a wav file extension?
There is a much better way to play mp3 files using WPF rather than Media Player. Don't have the code handy but I'm sure you'll find it.
www.dsmyth.net | www.dsmyth.net/wikiThursday, February 5, 2009 9:22 AM