0

I have a windows application, the main form (mainform.cs) include user controls which can be removed/added from main menu (i.e. user can close usercontrol from the main menu, usercontrols are layout within tabs in tabcontrols) When to close a usercontrol, I call dispose like this:

If (!MediaControl.IsDisposed)
     MediaControl.Dispose();

One of these usercontrols include axWindowsMediaPlayer control for playing media. When the application starts, it load that media usercontrol successfully, and able to play media without problems (add media files, change playlist items, play, pause ...etc all work) When I close that usercontrol from the main menu, media closed successfully. But when try to add it again, I get this message :

"Additional information: COM object that has been separated from its underlying RCW cannot be used."

The VS debug break at point when attempting to initialize the playlist:

    // Within media usercontrol
    protected override void OnFilesRefresh()
    {            
        foreach (string file in files)
        {
            WMPLib.IWMPMedia m1 = axWindowsMediaPlayer.newMedia(file);
            axWindowsMediaPlayer.currentPlaylist.appendItem(m1);
            .....
        }
    }

While files is array of file paths. newMedia method is causing the problem. How to dispose the media usercontrol which contain axWindowsMediaPlayer probably then initialize it again without problems ? Sorry for my English

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • Do search through SO before you post a question. You may not get exact answer but almost near one can be found. – Rahul Mar 22 '14 at 11:11

1 Answers1

0

A little search and found that the issue is described here:

Is it safe to call an RCW from a finalizer?

And here:

Release Excel Object In My Destructor

they have the same problem, Hope that helps.

Community
  • 1
  • 1
Monir Tarabishi
  • 716
  • 1
  • 16
  • 30
  • even found this article [Default VSPackage template in VS2013 SDK Throws Exception when exiting](http://social.msdn.microsoft.com/Forums/vstudio/en-US/06c0c8f3-e616-4c8c-9a62-aa87a6a63edb/default-vspackage-template-in-vs2013-sdk-throws-exception-when-exiting?forum=vsx) – Monir Tarabishi Mar 22 '14 at 11:06
  • thanks it works, all i had to do is to use Marshal.FinalReleaseComObject(player.currentMedia); same for playlist object. – user3449388 Mar 22 '14 at 17:56