views:

17

answers:

1

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....

A: 

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 ?

Timores