Under what circumstances does UIElement.UpdateLayout () call Environment.FailFast?

So, I have a control that calls UpdateLayout () in response to its mutable elements. This results in a stack trace that looks like this:

Description: The application requested completion of the process through System.Environment.FailFast (string message). Message: Unrecoverable system error. Stack: in System.Environment.FailFast (System.String) in MS.Internal.Invariant.FailFast (System.String, System.String) in MS.Internal.Invariant.Assert (Boolean, System.String) in System.Windows. Window.GetWindowMinMax () in System.Windows.Window.MeasureOverride (System.Windows.Size) in System.Windows.FrameworkElement.MeasureCore (System.Windows.Size) in System.Windows.UIElement.Measure (System.Windows.Size) in System.Windows.ContextLayoutManager.UpdateLayout () in System.Windows.UIElement.UpdateLayout () in

Obviously, in some circumstances, GetWindowMinMax () does not have Assert () of some type that calls the Environment.FailFast call. What conditions can I check before calling UpdateLayout to make sure that these circumstances do not occur in order to avoid this error?

+2
source share
2 answers

Take the reflector and look into the code for GetWindowMinMax. This statement:

Invariant.Assert (!this.IsCompositionTargetInvalid, 
    "IsCompositionTargetInvalid is supposed to be false here") ;

Thus, it looks like your window is not really created as a Win32 window, or its Win32 window has already been destroyed.

+2
source

I have sequential playback for this:

        hwndSource = new System.Windows.Interop.HwndSource(p);
        this.Visibility = System.Windows.Visibility.Hidden;
        hwndSource.RootVisual = this;

Installing RootVisual in a hidden window will call FailFast.

+2
source

All Articles