INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Another dev with out-of-process COM issue on JRMC11  (Read 2500 times)

secretsuperstar

  • Recent member
  • *
  • Posts: 26
Another dev with out-of-process COM issue on JRMC11
« on: July 13, 2005, 05:47:29 pm »

I've been having one of the same problems described by WickedEwok in my own automation app. I am using MediaCenter 11.0.307 and this is exactly what happens: When I attempt to create a new MJAutomationClass object, the MediaCenter app starts up but my calling program hangs (for around a minute) and eventually throws the following exception: System.Runtime.InteropServices.COMException (0x80080005): Server execution failed

Media Center is running normally, with only locally stored media files in its database. I have build 11.0.298 installed on another computer and I do not appear to get the same problem, although the code doesn't seem to completely work either (seem to be unable to retrieve playlists) but that's another matter. (That system doesn't have my development tools on it, so I haven't been able to determine what the code's doing yet... it isn't throwing any exceptions though, this much I know.)

Here is my code (C#). I'd appreciate some insight here. Thanks.

Code: [Select]
            try
            {
                // following line opens MediaCenter but results in this error after a long timeout:
                // System.Runtime.InteropServices.COMException (0x80080005): Server execution failed
                MJAutomationClass aut = new MJAutomationClass();

                aut.ShowProgram(1);

                MJPlaylistsAutomation playlists = aut.GetPlaylists();

                for (int i = 0; i < playlists.GetNumberPlaylists(); i++)
                {
                    MJPlaylistAutomation playlist = playlists.GetPlaylist(i);
                    listPlaylists.Text += playlist.Name;
                }
            }
            catch (Exception err)
            {
                Debug.WriteLine("butGetPlaylists_Click: " + err.ToString());
                MessageBox.Show("butGetPlaylists_Click: " + err.ToString());
            }

Logged

secretsuperstar

  • Recent member
  • *
  • Posts: 26
Re: Another dev with out-of-process COM issue on JRMC11
« Reply #1 on: July 13, 2005, 06:04:18 pm »

Also, here is the log data that is generated by MediaCenter when my app attempts to create the MJAutomationClass object... note the 'Revoking automation SDK' line:

4:00:22 PM: General: Log Reset: Logging reset
4:00:38 PM: Database: MCDB::Save: Start
4:00:38 PM: Database: MCDB::Save: Saving (bCleanDB: 0, bForce: 0)
4:00:38 PM: Database: MCDB::Save: Finish (0 ms)
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Start
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Source: CMCPlayerApp - ExitInstance
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Setting shutdown flags
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Saving data from UI
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Stopping playback
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Shutting down tools
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Saving last exit mode
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Destroying UI
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Running shutdown settings
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Setting global flags
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Clearing save timer
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Ending background threads
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Closing services
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Restoring system settings
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Revoking automation SDK
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Updating running flags
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Releasing objects
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Unloading skinning
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Deleting MC core
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Deleting global objects
4:00:52 PM: General: CMCShutdownHelper::CleanUp: Finish (120 ms)
Logged

secretsuperstar

  • Recent member
  • *
  • Posts: 26
Re: Another dev with out-of-process COM issue on JRMC11
« Reply #2 on: July 14, 2005, 04:06:03 pm »

Thanks to WickedEwok I have gotten past the automation issue. There were actually two different problems with my code:

1. I was blindly trying to instantiate a new MC object even if MC was already running, which results in the weird hang/exception described earlier. I followed his method of finding MC first, and using Marshal.GetActiveObject in that case.
2. I was instantiating MJAutomationClass instead of plain ol' MJAutomation. I still don't understand why my code compiled and ran, and I don't understand how MJAutomation is correct since it's not in the registry or object browser, but it works.

(Finally, there was a third problem with how I was attempting to stuff the playlist names into my app's list box... I was using the Text property instead of the Items property.)

Here's the corrected code:

Code: [Select]
            try
            {
                MJAutomation aut = null;

                IntPtr mcWindow = FindWindow("MJFrame", null);
                if (IntPtr.Zero != mcWindow)
                {   
                    aut = (MJAutomation) Marshal.GetActiveObject("MediaJukebox Application");
                }

                if (null == aut)
                {
                    // if MC is already running when we try to do the following, we'll get this exception:
                    // System.Runtime.InteropServices.COMException (0x80080005): Server execution failed
                    aut = new MJAutomation();
                    aut.ShowProgram(1);
                }

                MJPlaylistsAutomation playlists = aut.GetPlaylists();

                for (int i = 0; i < playlists.GetNumberPlaylists(); i++)
                {
                    MJPlaylistAutomation playlist = playlists.GetPlaylist(i);
                    Debug.WriteLine("Path: " + playlist.Path);
                    Debug.WriteLine("Name: " + playlist.Name);
                    listPlaylists.Items.Add(playlist.Name);
                }
            }
            catch (Exception err)
            {
                Debug.WriteLine("butGetPlaylists_Click: " + err.ToString());
                //MessageBox.Show("butGetPlaylists_Click: " + err.ToString());
            }
Logged

Zoner

  • Regular Member
  • World Citizen
  • ***
  • Posts: 198
  • nothing more to say...
Re: Another dev with out-of-process COM issue on JRMC11
« Reply #3 on: July 23, 2005, 02:51:08 am »

My experience is that there's no need to call FindWindow(), and it adds a potential fragility to your code.  Just call GetActiveObject(), and if it fails, then create your own object.
Logged

Zoner

  • Regular Member
  • World Citizen
  • ***
  • Posts: 198
  • nothing more to say...
Re: Another dev with out-of-process COM issue on JRMC11
« Reply #4 on: July 23, 2005, 03:13:10 am »

I have a question related to this - what is best practice when shutting down an app that is accessign MC11 via out-of-process COM?  I cannot find a way to allow MC11 to gracefully shutdown.  Maybe I will post a new thread about this.
Logged
Pages: [1]   Go Up