locked
Exception thrown in VisualTreeHelper.GetParent in windows 8.1 and VS 2013 RC RRS feed

  • Question

  • Hi ,

    We have faced some issue in VisualTreeHelper.GetParent().this method throws System.Exception while executing the below code.

    C#

     public static T FindVisualParent<T>(this DependencyObject dobj) where T : DependencyObject
     {
      DependencyObject parent = VisualTreeHelper.GetParent(dobj);
       if (parent == null && dobj is FrameworkElement)
         {
             parent = (dobj as FrameworkElement).Parent;
         }
         if (parent is T)
         {
            return parent as T;
         }
         else if (parent != null)
         {
            return parent.FindVisualParent<T>();
         }
         else
         {
            return null;
         }
    }

    please refer to the following stacktrace.

    StackTrace:

    System.Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
       at Windows.UI.Xaml.Media.VisualTreeHelper.GetParent(DependencyObject reference).

    the same code working fine with Windows8 and VS 2012.

    please help us to resolve this issue.

    Regards,
    Ramya


    Warm Regards, Rams

    Thursday, October 31, 2013 11:47 AM

Answers

  • Rams,

    If you need individual support then please open a support case and we would be happy to help you privately. The forums are a public location for community support.

    --Rob

    Thursday, November 21, 2013 6:28 AM
    Moderator

All replies

  • Hi,

    imho it could happen when dobj is null and you call VisualTreeHelper.GetParent(null)


    lh

    Thursday, October 31, 2013 1:55 PM
  • Hi

    Thanks for response.

    dobj is not Null.it is Panel(Grid /Canvas).

    The same Extension method is working fine in Vs2012.

    but throws exception in VS2013.


    Warm Regards, Rams

    Tuesday, November 5, 2013 6:05 AM
  • I'm having this same problem, was working fine in VS2012/8.0, crashes in VS2013/8.1

    Did you find a solution?

    Tuesday, November 5, 2013 2:47 PM
  • I'm not reproducing the error with your sample code in Visual Studio 2013 RTM:

        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Button Click="Button_Click">Click</Button>
        </Grid>
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                DependencyObject dobj = sender as DependencyObject;
                Panel parentPanel = dobj.FindVisualParent<Grid>();
                Debug.WriteLine("Found {0}", parentPanel);
                parentPanel = dobj.FindVisualParent<Panel>();
                Debug.WriteLine("Found {0}", parentPanel);
                parentPanel = dobj.FindVisualParent<StackPanel>();
                Debug.WriteLine("Found {0}", parentPanel);
            }

    Gives the expected output:

    Found Windows.UI.Xaml.Controls.Grid

    Found Windows.UI.Xaml.Controls.Grid

    Found

    If you're seeing this in RTM and not just in RC then the error may only occur with specific calling patterns. Can you please confirm that it reproduces in RTM and show how you are calling FindVisualParent and what the Xaml tree is you are searching when you get the error? Sharing a SkyDrive link with a minimal repro project would be ideal.

    --Rob

    Tuesday, November 5, 2013 10:38 PM
    Moderator
  • Hi Rob,<o:p></o:p>

    Is VS2013 RTM released? <o:p></o:p>

    For simple xaml tree, VisualTreeHelper is working fine. We are using somewhat complex xaml tree. <o:p></o:p>

    Here with I have provided the Screenshot of Xaml tree. Please refer to it as below.<o:p></o:p>

    Note:

    Finding the of Parent of Dependency object  throws this reported exception when Dispatcher of Dependency object is null.


    Warm Regards, Rams

    Wednesday, November 6, 2013 11:11 AM
  • Yes, VS2013 RTM is released.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, November 6, 2013 2:47 PM
    Moderator
  • Can you please share a SkyDrive link with a minimal repro project?

    I cannot reproduce the problem with a simple mimicry of the visual tree you show.

    --Rob

    Thursday, November 7, 2013 12:34 AM
    Moderator
  • Hi Rob,

    I have provided our dll with simple sample.Please refer to the sample from following skydrive link to reproduce the issue.

    Link:http://sdrv.ms/19mbpeE

    Replication Procedure:

    1.Run the sample

    2.Click on the Page

    3.Exeception will thrown.

    Please refer to the output Window to identify which element throws the reported issue.(the Dispatcher is null for that element)


    Warm Regards, Rams

    Thursday, November 14, 2013 6:56 AM
  • Hi Rams,

    Can you provide a minimal repro project so I can see exactly what the code is doing? A pre-compiled binary is not as helpful.

    --Rob

    Thursday, November 14, 2013 11:12 PM
    Moderator
  • Hi Rob/Rams

    Have you made any progress with this as I'm having the same issue (I'm also use the syncfusion diagram control on windows 8.1)

    Thanks

    Ross

    Wednesday, November 20, 2013 2:17 PM
  • Hi,

    I have spent too much time to reproduce this issue in a simple app, but I was not able to.I cannot provide you our source code as is not legal, that’s why we provided a dll.

    I have logged an issue though connect.microsoft.com. 

    Link:https://connect.microsoft.com/VisualStudio/feedback/details/809194/issue-with-vs2013-in-windows-8-1

    @Microsoft: please take a look at this, this is affecting our product and customers.  

    Please let me know if there is any other things I can share (maybe we can provide debug version of the dll).

    Regards,Ramya


    Warm Regards, Rams

    Thursday, November 21, 2013 5:24 AM
  • Rams - it's interesting that you say it's not legal - I know that with our syncfusion membership it includes a copy of the source code, so there must be a way to allow it!

    Thanks

    Ross

    Thursday, November 21, 2013 5:28 AM
  • Rams,

    If you need individual support then please open a support case and we would be happy to help you privately. The forums are a public location for community support.

    --Rob

    Thursday, November 21, 2013 6:28 AM
    Moderator