在什么情况下可以UIElement.UpdateLayout()调用Environment.FailFast?情况下、UIElement、UpdateLayout、Environment

2023-09-04 04:14:12 作者:画地为牢

所以我有,根据其项目被更改的控制,调用UpdateLayout请()。这导致堆栈跟踪如下所示:

So I have a control which, in response to its items being changed, calls UpdateLayout(). This results in a stack trace that looks like the following:

说明:应用程序请求的过程终止通过   System.Environment.FailFast(字符串消息)。消息:不可恢复   系统错误。堆栈:在System.Environment.FailFast(System.String)   在MS.Internal.Invariant.FailFast(System.String,System.String)在   MS.Internal.Invariant.Assert(布尔,System.String)在   System.Windows.Window.GetWindowMinMax()在   System.Windows.Window.MeasureOverride(System.Windows.Size)在   System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)在   System.Windows.UIElement.Measure(System.Windows.Size)在   System.Windows.ContextLayoutManager.UpdateLayout()在   System.Windows.UIElement.UpdateLayout()在

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

显然,在某些情况下,GetWindowMinMax()是失败的某种类型的断言(),这是造成一个调用Environment.FailFast。我可以在调用UpdateLayout请确保这些情况不会发生,以避免遇到此错误之前,请检查什么样的条件?

Clearly, under some circumstances, GetWindowMinMax() is failing an Assert() of some sort, which is causing an call to Environment.FailFast. What conditions can I check before calling UpdateLayout to ensure that these circumstances do not occur in order to avoid encountering this error?

推荐答案

取反射器和偷看$ C $下 GetWindowMinMax 。这是断言:

Take Reflector and peek at the code for GetWindowMinMax. This is the assert:

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

所以,这样看来,你的窗口是不是真的创建为一个Win32窗口尚未或其Win32的窗口已经销毁。

So it would appear that your window is not really created as a Win32 window yet or its Win32 window is already destroyed.