Exception handling in COM object


New member
Oct 5, 2009
Programming Experience
Hi friends,

I have used mediaplayer as COM object in my form and put some buttons like play, pause etc. which is getting called in my MDI parent form. It was working fine for few days, but when i added Speech Recognition on the form and it started giving this exception..

System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at WMPLib.IWMPPlayer4.get_controls()
at AxWMPLib.AxWindowsMediaPlayer.get_Ctlcontrols()
at Ground_Replay_System.mediaPlayerForm.pauseButton_Click(Object sender, EventArgs e) in E:\mediaPlayerTest\Forms\mediaPlayer.vb:line 58
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at Ground_Replay_System.mediaPlayerForm.recognizer_SpeechRecognized(Object sender, SpeechRecognizedEventArgs e) in E:\mediaPlayerTest\Forms\mediaPlayer.vb:line 221
at System.Speech.Recognition.SpeechRecognitionEngine.SpeechRecognizedProxy(Object sender, SpeechRecognizedEventArgs e)

From some reading i found that this can happen when GC clears the COM, and still it is being refered.
But i have added winmediaPlayer at design time, so i guess it will not dispose till form is present like at the end of routine..:confused:

Any Suggestions are welcome.
Top Bottom