Hi,
I was moving a floating window when the below exception occured.
Our application uses multiple top-level windows in different appdomains, and a ribbon with office 2010 style backstage.
Infragistics version is currently 2013.1.
Any insights? Anything we can do to prevent it, since the affected window sometimes hangs afterward and the application must be manually terminated.
App_DispatcherUnhandledExceptionSystem.InvalidOperationException: Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed. at System.Windows.Window.CoerceVisibility(DependencyObject d, Object value) at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks) at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding) at Infragistics.Windows.Controls.ToolWindowHostWindow.DeferShowHelper.Show(Boolean activate) at Infragistics.Windows.Controls.ToolWindow.DeferredShowInfo.ProcessShow(Boolean cancel) at Infragistics.Windows.DockManager.DockManagerUtilities.ShowToolWindow(ToolWindow window, FrameworkElement owner, Boolean activate) at Infragistics.Windows.DockManager.Dragging.DragManager.CreateFloatingPreviewWindow(Point point, Size size) at Infragistics.Windows.DockManager.Dragging.MoveWindowAction.PerformAction(DragManager dragManager, Boolean isPreview) at Infragistics.Windows.DockManager.Dragging.DragManager.ProcessDragMove(IInputDeviceInfo e, Nullable`1 windowRect) at Infragistics.Windows.DockManager.Dragging.DragManager.StartDrag(FrameworkElement element, Point mouseDownPosition, IInputDeviceInfo e, Boolean processMove, Boolean isWindowDragMode) at Infragistics.Windows.DockManager.Dragging.DragManager.OnPendingDragElementMouseMove(Object sender, MouseEventArgs e) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.Input.InputManager.ProcessStagingArea() 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, WindowMessage 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, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Sorry for the delay. I guess you haven't isolated it any further. If you would, can you please try adding the following class into your exe assembly:
using System;using System.Diagnostics;using System.Windows; namespace ToolWindowDebugger{ public static class DebugHelper { #region IsAttached public static readonly DependencyProperty IsAttachedProperty = DependencyProperty.RegisterAttached("IsAttached", typeof(bool), typeof(DebugHelper), new FrameworkPropertyMetadata((bool)false, new PropertyChangedCallback(OnIsAttachedChanged))); public static bool GetIsAttached(DependencyObject d) { return (bool)d.GetValue(IsAttachedProperty); } public static void SetIsAttached(DependencyObject d, bool value) { d.SetValue(IsAttachedProperty, value); } private static readonly object IsInShowId = new object(); private static void OnIsAttachedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var w = Window.GetWindow(d); if (w != null && w.GetType().FullName == "Infragistics.Windows.Controls.ToolWindowHostWindow") { var fe = d as FrameworkElement; if (fe != null && fe.TemplatedParent == w) { w.Tag = IsInShowId; w.Closing += OnToolWindowClosing; w.ContentRendered += OnToolWindowContentRendered; } } } static void OnToolWindowContentRendered(object sender, EventArgs e) { // if we got here then we're passed the OnSourceInitialized... var w = sender as Window; w.Tag = null; w.Closing -= OnToolWindowClosing; w.ContentRendered -= OnToolWindowContentRendered; } static void OnToolWindowClosing(object sender, System.ComponentModel.CancelEventArgs e) { var w = sender as Window; if (w.Tag == IsInShowId) { var stack = Environment.StackTrace; if (stack.Contains("at System.Windows.Window.Show()")) { Debugger.Break(); } } } #endregion // IsAttached }}
using System;using System.Diagnostics;using System.Windows;
namespace ToolWindowDebugger{ public static class DebugHelper { #region IsAttached
public static readonly DependencyProperty IsAttachedProperty = DependencyProperty.RegisterAttached("IsAttached", typeof(bool), typeof(DebugHelper), new FrameworkPropertyMetadata((bool)false, new PropertyChangedCallback(OnIsAttachedChanged)));
public static bool GetIsAttached(DependencyObject d) { return (bool)d.GetValue(IsAttachedProperty); }
public static void SetIsAttached(DependencyObject d, bool value) { d.SetValue(IsAttachedProperty, value); }
private static readonly object IsInShowId = new object();
private static void OnIsAttachedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var w = Window.GetWindow(d);
if (w != null && w.GetType().FullName == "Infragistics.Windows.Controls.ToolWindowHostWindow") { var fe = d as FrameworkElement;
if (fe != null && fe.TemplatedParent == w) { w.Tag = IsInShowId; w.Closing += OnToolWindowClosing; w.ContentRendered += OnToolWindowContentRendered; } } }
static void OnToolWindowContentRendered(object sender, EventArgs e) { // if we got here then we're passed the OnSourceInitialized... var w = sender as Window; w.Tag = null; w.Closing -= OnToolWindowClosing; w.ContentRendered -= OnToolWindowContentRendered; }
static void OnToolWindowClosing(object sender, System.ComponentModel.CancelEventArgs e) { var w = sender as Window;
if (w.Tag == IsInShowId) { var stack = Environment.StackTrace;
if (stack.Contains("at System.Windows.Window.Show()")) { Debugger.Break(); } } }
#endregion // IsAttached }}
Then add the following into your App's Resources:
<Style TargetType="ContentPresenter" xmlns:igDebug="clr-namespace:ToolWindowDebugger"> <Setter Property="igDebug:DebugHelper.IsAttached" Value="True" /> </Style>
Then try to reproduce the problem. In theory it should break into the debugger when the Window is being closed while the show is in progress. If it does then please provide the call stack at that point.
Thanks.
Hmmm... I do see the this.IsDisposed == true. So you are right it is getting closed somehow. The this.Title was set to an empty string so I'm not sure if the window I undocked was the same window that is causing this exception.
I'm wondering if changing
IntPtr handle = new WindowInteropHelper((Window) this).Handle;
to
IntPtr handle = new WindowInteropHelper((Window) this).EnsureHandler();
would fix this issue for us. The value of this._isClosing = false at the time of the error so I'm still pretty sure it isn't closing. Seems like the native window isn't ready yet.
In ToolWindowHostWindow.cs
protected override void OnSourceInitialized(EventArgs e) { this.SetFlag(ToolWindowHostWindow.InternalFlags.HasSourceBeenInitialized, true); IntPtr handle = new WindowInteropHelper((Window) this).Handle; HwndSource.FromHwnd(handle).AddHook(new HwndSourceHook(this.WndProc)); PresentationSource.AddSourceChangedHandler((IInputElement) this, new SourceChangedEventHandler(this.OnPresentationSourceChanged)); if (this._content != null) { this.SetBinding(ToolWindowHostWindow.WindowStateInternalProperty, (BindingBase) Utilities.CreateBindingObject(ToolWindow.WindowStateProperty, BindingMode.TwoWay, (object) this._content)); if (this._content != null && this.WindowState != WindowState.Normal) { Rect restoreBounds = this._content.GetRestoreBounds(false); if (NativeWindowMethods.GetWindowState((Window) this) == WindowState.Normal && this.WindowState == WindowState.Minimized && !restoreBounds.IsEmpty) this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Delegate) new SendOrPostCallback(this.AsyncInitializeRestoreBounds), (object) restoreBounds); else this.SetRestoreBounds(handle, restoreBounds); } this.UseSystemNonClientArea = this.UseSystemNonClientArea; } this.VerifyWindowStyleBits(handle); ToolWindowHostWindow.UpdateAllowClose((Window) this, this.AllowClose); this.VerifyRelativePositionBinding(); this.SynchronizeLocation(true); base.OnSourceInitialized(e); this.VerifyIsInView(false, true, false); }
I was able to test with the 2336 version and the issue still happens every time. Still unable to reproduce in a test app even while using the same OCX control in the pane. Attached is the video showing the flow and how the exception is happening. Note the undocked window is not closed or closing when the exception occurs. It still seems like a timing with this call that assumes it would be visible. If it was closing or closed wouldn't the undocked window go away?
I believe the last SR for 13.1 was Bld 2336. If you're logged in and its registered to you then you should see it under keys and downloads.