Need help from fellow programmer (1 Viewer)

Inker

Retired Team Member
  • Premium Supporter
  • December 6, 2004
    2,055
    318
    I just cannot figure this out:

    Take the following code:
    Code:
    GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
    throws InvalidCastException telling me:
    Das Objekt des Typs MediaPortal.Dialogs.GUIDialogYesNo kann nicht in Typ MediaPortal.Dialogs.GUIDialogYesNo umgewandelt werden.

    Yeah.......right. If I do:
    Code:
    GUIDialogYesNo dlgYesNo = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO) as GUIDialogYesNo;
    then dlgYesNo == null.....because again it can't cast.

    GUIDialogYesNo dlgYesNo = new GUIDialogYesNo(); works, but I cannot use that window as it throws a nullreference exception as soon as I do doModul

    GUIWindow wind = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
    also works, because no cast is involved.

    Now, GetType().Fullname both return MediaPortal.Dialogs.GUIDialogYesNo
    GetType().GUID both return the exact same value too
    for new GUIDialogYesNo() and GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO)

    I am compiling against the exact same Dialogs.dll as MP is loading at runtime.

    It also happens with
    Code:
    GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
    but there I can go the route of:
    Code:
    IDialogbox dlg = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
    unfortunatly guidialogyesno does not implement such an interface.

    I guess the question is.....what can cause a type to be uncastable to itself?

    It used to always work fine, but suddently stopped, unfortunatly I don't know what I changed or even exactly when it occured.
     

    chrholm

    Portal Pro
    June 20, 2005
    64
    2
    47
    Copenhagen
    Home Country
    Denmark Denmark
    I have very little experience with .NET, but I have seen very similar things in Java. It is always caused by the class being loaded twice by different classloaders. I'm not sure if .NET have a similar concept, but I would look duplicate entries of the class in question. Maybes its being loaded from two different places?
     

    Inker

    Retired Team Member
  • Premium Supporter
  • December 6, 2004
    2,055
    318
    Thnx, do you know how I would go about checking this, and then how to prevent it? All I do is add a reference to Dialogs.dll during compiletime.
     

    G.B. Wolf

    MP Donator
  • Premium Supporter
  • March 22, 2007
    227
    3
    Braunschweig
    Home Country
    Germany Germany
    Hmm... strange... have you tried just:

    Code:
    GUIDialogYesNo dlgYesNo = GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);

    So just dropping the cast?
     

    patrick

    Portal Pro
    April 20, 2005
    608
    45
    Southeast
    Home Country
    United States of America United States of America
    I just cannot figure this out:

    I cannot reproduce this.

    private build of MP with SVN 15Mar2008
    private build if MP-TVSeries SVN 15Mar2008
    Monochrome skin from MP downloads (v1.6 10Mar2008)

    I uncommented most of your code for the YesNo dialog in your "Ask user to Resume" put in in a try/catch to check any errors but got none :)

    I did not try other skins as I did not know which one you use or even support the plugin
    Also could not find just the TVSeries skin files to download for skins.
    Did not look very hard though ;)


    Code I used below, SS attached.

    Code:
                    #region Ask user to Resume
                    if (timeMovieStopped > 0)
                    {
                       try
                       {
                          GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                          //sender.YesNoOkDialog(new WindowPlugins.GUITVSeries.Feedback.ChooseFromYesNoDescriptor());
                          if (null != dlgYesNo)
                          {
                             dlgYesNo.SetHeading(GUILocalizeStrings.Get(900)); //resume movie?
                             dlgYesNo.SetLine(1, m_currentEpisode.onlineEpisode.CompleteTitle);
                             dlgYesNo.SetLine(2, GUILocalizeStrings.Get(936) + " " + Utils.SecondsToHMSString(timeMovieStopped));
                             dlgYesNo.SetDefaultToYes(true);
                             dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                             if (!dlgYesNo.IsConfirmed) // reset resume data in DB
                             {
                                timeMovieStopped = 0;
                                m_currentEpisode[DBEpisode.cStopTime] = timeMovieStopped;
                                m_currentEpisode.Commit();
                             }
                          }
                       }
                       catch (Exception exc)
                       {
                          MPTVSeriesLog.Write("TVSeriesPlugin.VideoHandler.ResumeOrPlay()\r\n" + exc.ToString());
                          MPTVSeriesLog.Write("TVSeriesPlugin.VideoHandler.ResumeOrPlay()\r\n" + exc.InnerException.ToString());
                          MPTVSeriesLog.Write("TVSeriesPlugin.VideoHandler.ResumeOrPlay()\r\n" + exc.StackTrace.ToString());
                       }
                    }
                    #endregion


    HTH,
    patrick
     

    Inker

    Retired Team Member
  • Premium Supporter
  • December 6, 2004
    2,055
    318
    Interesting patrick, I'll need to try again, but I tried with two different mp svn's to make sure it wasnt that. Anyways thnx a ton for trying and letting me know, I'll let you know if it works for me too :)


    PS: Psycho Reptile seems to be a really grateful guy :)
     

    James

    Retired Team Member
  • Premium Supporter
  • May 6, 2005
    1,385
    67
    Switzerland
    Hi Inker,

    I think your problem is that you have two copies of the same DLL. One is being used to create this object and the second here to try and access it.

    If this is true. Then .NET thinks they are different objects even if the name is the same.

    Check that there is only one DLL and make sure it is in a search path accessable by all.

    /James
     

    Inker

    Retired Team Member
  • Premium Supporter
  • December 6, 2004
    2,055
    318
    Hey James,

    I think you mean like chrholm said, and it makes sense to me, but I don't really know what to do about it or even how to check, on the other hand I must admit I had very limited time since the weekend so it's not like I spend a great amount of time looking into it.

    Just to help me understand this two dll thing, is this even a compile-time thingy (as in I'm referencing the dll twice somehow) or is it something that happens during runtime? Sorry, but I have no experience with that kinda thing.
     

    patrick

    Portal Pro
    April 20, 2005
    608
    45
    Southeast
    Home Country
    United States of America United States of America
    Just to help me understand this two dll thing

    I think James and chrholm are correct.

    Check to make sure you do not have a copy of the Dialogs.dll file in both the MP folder AND the MP plugins\windows folder.
    (Should only be in the plugins\windows folder)

    I just "copied" to the MP folder to test:
    Code:
    System.InvalidCastException: Unable to cast object of type 'MediaPortal.Dialogs.GUIDialogYesNo' to type 'MediaPortal.Dialogs.GUIDialogYesNo'.

    HTH,
    patrick
     

    Users who are viewing this thread

    Top Bottom