设置子用户控件的 SizeToContent 会导致 FatalExecutionEngineError
我在视图基类中添加了一个依赖属性,该属性应该允许子 UserControls 在父窗口上设置一些属性,其中之一是 SizeToContent。当我的 OnSizeToContent 方法运行时,当它尝试将主窗口的 SizeToContent 从 WidthAndHeight 更改为手动时,我收到这个奇怪的错误:
检测到 FatalExecutionEngineError 消息:运行时遇到致命错误。错误的地址位于线程 0x17e8 上的 0x58e29ddd。错误代码为0x80131623。此错误可能是 CLR 中的错误或用户代码的不安全或不可验证部分中的错误。此错误的常见来源包括 COM 互操作或 PInvoke 的用户封送错误,这可能会损坏堆栈。
以前从未见过此错误,我不知道如何调试此错误,搜索没有找到任何相关内容。
有人能破译这个吗?
private static void OnSizeToContentChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
if (Designer.IsInDesignMode)
return;
((ViewBase) o).MainWindow.SizeToContent = (SizeToContent) e.NewValue;
}
private static readonly DependencyProperty SizeToContentProperty =
DependencyProperty.Register("SizeToContent", typeof(SizeToContent), typeof(ViewBase),
new UIPropertyMetadata(SizeToContent. WidthAndHeight, OnSizeToContentChanged));
这是 OnSizeToContentChanged 之后的部分堆栈跟踪:
WindowsBase.dll!MS.Internal.Invariant.FailFast(string message, string detailMessage) + 0x35 bytes
WindowsBase.dll!MS.Internal.Invariant.Assert(bool condition) + 0x2b bytes
PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.Grid}) + 0xc4 bytes
PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.ItemsPresenter}) + 0x158 bytes
PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.Border}) + 0x158 bytes
PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.ItemsControl}) + 0x158 bytes
PresentationCore.dll!System.Windows.Media.Visual.AddVisualChild(System.Windows.Media.Visual child = {System.Windows.Controls.ItemsControl}) + 0x4f bytes
PresentationFramework.dll!System.Windows.FrameworkElement.TemplateChild.set(System.Windows.UIElement value) + 0x32 bytes
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.UseContentTemplate.BuildVisualTree(System.Windows.FrameworkElement container) + 0xa4 bytes
PresentationFramework.dll!System.Windows.StyleHelper.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, System.Windows.DependencyObject container, System.Windows.FrameworkElementFactory templateRoot, int lastChildIndex, System.Collections.Specialized.HybridDictionary childIndexFromChildID, System.Windows.FrameworkTemplate frameworkTemplate) + 0x1c9 bytes
PresentationFramework.dll!System.Windows.FrameworkTemplate.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> templateDataField, System.Windows.FrameworkElement container = {System.Windows.Controls.ContentPresenter}) + 0x3b bytes
PresentationFramework.dll!System.Windows.FrameworkElement.ApplyTemplate() + 0x7b bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x40 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationFramework.dll!System.Windows.Documents.AdornerDecorator.MeasureOverride(System.Windows.Size constraint) + 0x61 bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d6 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint) + 0x18c bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d6 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint) + 0x18f bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d6 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationFramework.dll!System.Windows.Window.MeasureOverrideHelper(System.Windows.Size constraint) + 0x14b bytes
PresentationFramework.dll!System.Windows.Window.MeasureOverride(System.Windows.Size availableSize) + 0xd6 bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x526 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationCore.dll!System.Windows.Interop.HwndSource.SetLayoutSize() + 0xbf bytes
PresentationCore.dll!System.Windows.Interop.HwndSource.SizeToContent.set(System.Windows.SizeToContent value) + 0x60 bytes
PresentationFramework.dll!System.Windows.Window.OnSizeToContentChanged(System.Windows.SizeToContent sizeToContent) + 0x60 bytes
PresentationFramework.dll!System.Windows.Window._OnSizeToContentChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0x52 bytes
WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x4c bytes
PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x50 bytes
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) + 0x3c bytes
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex = {System.Windows.EntryIndex}, System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry = {System.Windows.EffectiveValueEntry}, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) + 0x723 bytes
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal) + 0x2eb bytes
WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) + 0x35 bytes
PresentationFramework.dll!System.Windows.Window.SizeToContent.set(System.Windows.SizeToContent value) + 0x4c bytes
> UCL.exe!UCL.Classes.ViewBase.OnSizeToContentChanged(System.Windows.DependencyObject o = {UCL.Views.EditorView}, System.Windows.DependencyPropertyChangedEventArgs e = {System.Windows.DependencyPropertyChangedEventArgs}) Line 50 + 0x67 bytes C#
编辑#1:
设置 SizeToContent 后,我正在查看窗口的属性。 IsMeasureValid = false,IsArrangeValid = true ,但来自 msdn:
如果 IsMeasureValid 为 false,则 IsArrangeValid 也必须为 false(通过布局过程的强制逻辑,如果测量首先有效,排列就不可能有效)。
我有一个类似的 ResizeMode 属性,当它发生变化时,似乎设置了 IsMeasureValid=false。
我应该注意,我这样做是为了将 ResizeMode="CanResizeWithGrip" SizeToContent="Manual" 添加到我的 XAML 中。
我用 InvalidateArrange 和 UpdateLayout 做了一些实验,但没有骰子。 没有它我也可以生活,但我真的很想弄清楚......
I've added a dependency property to my view base class, that is supposed to allow the child UserControls to set some properties on the parent window, one being SizeToContent. When my OnSizeToContent method runs, when it tries to change the main windows's SizeToContent from WidthAndHeight to Manual, I get this odd error:
FatalExecutionEngineError was detected
Message: The runtime has encountered a fatal error. The address of the error was at 0x58e29ddd, on thread 0x17e8. The error code is 0x80131623. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
Never seen this error before, I have no idea how to debug this, searching didn't find anything relevant.
Can anyone decipher this?
private static void OnSizeToContentChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
if (Designer.IsInDesignMode)
return;
((ViewBase) o).MainWindow.SizeToContent = (SizeToContent) e.NewValue;
}
private static readonly DependencyProperty SizeToContentProperty =
DependencyProperty.Register("SizeToContent", typeof(SizeToContent), typeof(ViewBase),
new UIPropertyMetadata(SizeToContent. WidthAndHeight, OnSizeToContentChanged));
Here's the partial stack trace after OnSizeToContentChanged:
WindowsBase.dll!MS.Internal.Invariant.FailFast(string message, string detailMessage) + 0x35 bytes
WindowsBase.dll!MS.Internal.Invariant.Assert(bool condition) + 0x2b bytes
PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.Grid}) + 0xc4 bytes
PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.ItemsPresenter}) + 0x158 bytes
PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.Border}) + 0x158 bytes
PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.ItemsControl}) + 0x158 bytes
PresentationCore.dll!System.Windows.Media.Visual.AddVisualChild(System.Windows.Media.Visual child = {System.Windows.Controls.ItemsControl}) + 0x4f bytes
PresentationFramework.dll!System.Windows.FrameworkElement.TemplateChild.set(System.Windows.UIElement value) + 0x32 bytes
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.UseContentTemplate.BuildVisualTree(System.Windows.FrameworkElement container) + 0xa4 bytes
PresentationFramework.dll!System.Windows.StyleHelper.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, System.Windows.DependencyObject container, System.Windows.FrameworkElementFactory templateRoot, int lastChildIndex, System.Collections.Specialized.HybridDictionary childIndexFromChildID, System.Windows.FrameworkTemplate frameworkTemplate) + 0x1c9 bytes
PresentationFramework.dll!System.Windows.FrameworkTemplate.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> templateDataField, System.Windows.FrameworkElement container = {System.Windows.Controls.ContentPresenter}) + 0x3b bytes
PresentationFramework.dll!System.Windows.FrameworkElement.ApplyTemplate() + 0x7b bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x40 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationFramework.dll!System.Windows.Documents.AdornerDecorator.MeasureOverride(System.Windows.Size constraint) + 0x61 bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d6 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint) + 0x18c bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d6 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint) + 0x18f bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d6 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationFramework.dll!System.Windows.Window.MeasureOverrideHelper(System.Windows.Size constraint) + 0x14b bytes
PresentationFramework.dll!System.Windows.Window.MeasureOverride(System.Windows.Size availableSize) + 0xd6 bytes
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x526 bytes
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes
PresentationCore.dll!System.Windows.Interop.HwndSource.SetLayoutSize() + 0xbf bytes
PresentationCore.dll!System.Windows.Interop.HwndSource.SizeToContent.set(System.Windows.SizeToContent value) + 0x60 bytes
PresentationFramework.dll!System.Windows.Window.OnSizeToContentChanged(System.Windows.SizeToContent sizeToContent) + 0x60 bytes
PresentationFramework.dll!System.Windows.Window._OnSizeToContentChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0x52 bytes
WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x4c bytes
PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x50 bytes
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) + 0x3c bytes
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex = {System.Windows.EntryIndex}, System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry = {System.Windows.EffectiveValueEntry}, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) + 0x723 bytes
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal) + 0x2eb bytes
WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) + 0x35 bytes
PresentationFramework.dll!System.Windows.Window.SizeToContent.set(System.Windows.SizeToContent value) + 0x4c bytes
> UCL.exe!UCL.Classes.ViewBase.OnSizeToContentChanged(System.Windows.DependencyObject o = {UCL.Views.EditorView}, System.Windows.DependencyPropertyChangedEventArgs e = {System.Windows.DependencyPropertyChangedEventArgs}) Line 50 + 0x67 bytes C#
Edit #1:
I'm looking at the properties of my window right when the SizeToContent is set.
IsMeasureValid = false, and IsArrangeValid = true
, yet from msdn:
If IsMeasureValid is false, IsArrangeValid must also be false (by the enforced logic of the layout process, arrangement cannot be valid without measurement first being valid).
I've got a similar property for ResizeMode, and when that changes, seems to set the IsMeasureValid=false.
I should note, I did this so I could add ResizeMode="CanResizeWithGrip" SizeToContent="Manual" to my XAML.
I did some experimenting with InvalidateArrange and UpdateLayout, but no dice.
I can live without it, but I'd really like to figure it out....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 System.Windows.UIElement.PropagateResumeLayout,如果调用该方法时测量或排列过程已在进行中,则断言将失败。
您的 UserControl 是否有可能在调整大小时或 WPF 要求其执行布局或排列过程的任何其他状态时尝试设置 SizeToContent 属性?
Looking at System.Windows.UIElement.PropagateResumeLayout, the assert fails if either a measure or arrange pass is already in progress when the method is called.
Is it possible that your UserControl tries to set the SizeToContent property while it is being resized or any other state where WPF asked it to perform a layout or arrange pass ?