I get an exception and it goes through your code

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 12 years ago by Simon Deguire
Version: 3.0.0405
Platform: .NET 3.0
Environment: Windows XP (32-bit)
Avatar
The exception is "'System.Windows.Documents.Run' is not a Visual or Visual3D."

I get this on a particular occasion, I cannot easily reproduce it.
Anyway, it seems that you let a DependencyObject go through System.Windows.Media.VisualTreeHelper.GetParent(DependencyObject reference)
but the doc of getparent specifies that "The value of reference can represent either a Visual or Visual3D object."

Maybe you should wrap this call with a try catch or check if the object is a visual or a visual3d before calling the method.

Here's the stacktrace

Quote:
at MS.Internal.Media.VisualTreeUtils.AsVisual(DependencyObject element, Visual& visual, Visual3D& visual3D)
at System.Windows.Media.VisualTreeHelper.GetParent(DependencyObject reference)
at ActiproSoftware.Windows.Media.VisualTreeHelperExtended.GetAncestor(DependencyObject source, Type desiredType)
at ActiproSoftware.Windows.Media.VisualTreeHelperExtended.GetCurrentOrAncestor(DependencyObject source, Type desiredType)
at ActiproSoftware.Windows.Controls.Ribbon.RibbonWindow.a(Point A_0)
at ActiproSoftware.Windows.Controls.Ribbon.RibbonWindow.OnPreviewMouseMove(MouseEventArgs e)
at System.Windows.UIElement.OnPreviewMouseMoveThunk(Object sender, MouseEventArgs e)
at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.ContentElement.RaiseEventImpl(RoutedEventArgs args)
at System.Windows.ContentElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.Show()
at System.Windows.Window.ShowDialog()

    Comments (3)

    Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
    Avatar
    Thanks Simon, I've updated all the code that calls VisualTreeHelper.GetParent so that it now checks for a Visual/Visual3D source object first. This change will be in the next maintenance release.


    Actipro Software Support

    Posted 12 years ago by Simon Deguire
    Avatar
    Will this be released in a future version of Ribbon (for WPF) 1.0.x Maintenance Release?
    We can't use the version 3 (some problem with the status bar not showing that I don't have time to investigate right now), so for now but we are stuck with this bug and it's a crash we can't recover properly..
    Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
    Avatar
    Hi Simon,

    Send us an email and we can either work to get you an updated v1.0 maintenance release or help you get updated to v3.0.


    Actipro Software Support

    The latest build of this product (v2019.1 build 0682) was released 3 days ago, which was after the last post in this thread.

    Add Comment

    Please log in to a validated account to post comments.