New exception in Beta 2 makes no sense?

I do not have a clue on what this exception means. From the stack trace I see none of my code in the call stack. It appears to be a problem with applying a property value that changes the template of an element. Any help would be welcome.

"Dispatcher processing has been suspended, but messages are still being processed."

at System.Windows.Threading.Dispatcher.WndProcHook(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, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
at System.Windows.StyleHelper.LoadOptimizedTemplateContent(DependencyObject container, ParserContext parserContext, OptimizedTemplateContent optimizedTemplateContent, FrameworkTemplate frameworkTemplate, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
at System.Windows.FrameworkElement.ApplyTemplate()
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureSingleChild(UIElement child, Size constraint)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(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, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at ModelMagicUI.MyApp.Main() in C:\Documents and Settings\Michael Latta\My Documents\Visual Studio 2005\Projects\ModelMagic\ModelMagicUI\obj\Debug\MyApp.g.cs:line 59




Answer this question

New exception in Beta 2 makes no sense?

  • SameerM

    Since I have no access to the code and no way to even know which template it is expanding I doubt I am going to figure out why it is doing that. I will however attempt to create a small example that does something like what the application does (respond to a property change by changing a bound property that uses a data template to replace the UI element that caused the property value to change). I will let you know if I suceed in that attempt.

  • Dmitry Titov MSFT

    It will not show the value of the BamlRecord saying it has been optimized away. Here is a more detailed stack trace with external code shown. I do not know if this helps any. I also noticed that it is applying the template for one of my custom controls (that does not really do that much). I can probably make a small example that does a similar thing to this, and hope it also shows this problem.

    WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x17b bytes
    WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 331926, int msg = 50025, System.IntPtr wParam = 0, System.IntPtr lParam = 0, ref bool handled = false) + 0x87 bytes
    WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x10f bytes
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {System.Windows.Threading.DispatcherOperationCallback}, object args = {Dimensions:[4]}, bool isSingleParameter = true) + 0x4a bytes
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x3f bytes
    WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, bool isSingleParameter) + 0x140 bytes
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) + 0x3d bytes
    WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 331926, int msg = 50025, System.IntPtr wParam = 0, System.IntPtr lParam = 0) + 0x196 bytes
    [Native to Managed Transition]
    > PresentationFramework.dll!System.Windows.Markup.BamlRecordReader.ReadRecord(System.Windows.Markup.BamlRecord bamlRecord) + 0x62c bytes
    PresentationFramework.dll!System.Windows.StyleHelper.LoadOptimizedTemplateContent(System.Windows.DependencyObject container = {ModelMagicControls.GradientEditor: Linear Fill}, System.Windows.Markup.ParserContext parserContext = {System.Windows.Markup.ParserContext}, System.Windows.Markup.OptimizedTemplateContent optimizedTemplateContent, System.Windows.FrameworkTemplate frameworkTemplate = {System.Windows.Controls.ControlTemplate}, System.Windows.Markup.IComponentConnector componentConnector, System.Windows.Markup.IStyleConnector styleConnector, System.Collections.Generic.List<System.Windows.DependencyObject> affectedChildren, System.Windows.UncommonField<System.Collections.Hashtable> templatedNonFeChildrenField) + 0x203 bytes
    PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadContent(System.Windows.DependencyObject container, System.Collections.Generic.List<System.Windows.DependencyObject> affectedChildren, System.Windows.UncommonField<System.Collections.Hashtable> templatedNonFeChildrenField) + 0xc9 bytes
    PresentationFramework.dll!System.Windows.StyleHelper.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, System.Windows.DependencyObject container = {ModelMagicControls.GradientEditor: Linear Fill}, System.Windows.FrameworkElementFactory templateRoot, int lastChildIndex, System.Collections.Specialized.HybridDictionary childIndexFromChildID, System.Windows.FrameworkTemplate frameworkTemplate) + 0x1a3 bytes
    PresentationFramework.dll!System.Windows.FrameworkElement.ApplyTemplate() + 0x60 bytes
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x2f bytes
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x218 bytes
    PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCell(int cell, bool forceInfinityV) + 0x16a bytes
    PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, System.Windows.Size referenceSize, bool ignoreDesiredSizeU = false, bool forceInfinityV = false) + 0x61 bytes
    PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint) + 0x259 bytes
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1b0 bytes
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x218 bytes
    PresentationFramework.dll!MS.Internal.Helper.MeasureSingleChild(System.Windows.UIElement child = {System.Windows.Controls.Grid}, System.Windows.Size constraint) + 0x3c bytes
    PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size constraint) + 0x42 bytes
    PresentationFramework.dll!System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size constraint) + 0x16 bytes
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1b0 bytes
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x218 bytes
    PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() + 0x188 bytes
    PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayoutCallback(object arg) + 0x19 bytes
    PresentationCore.dll!System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork() + 0x10 bytes
    PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() + 0x77 bytes
    PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget = null) + 0x8a bytes
    PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget) + 0x28 bytes
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {System.Windows.Threading.DispatcherOperationCallback}, object args = null, bool isSingleParameter = true) + 0x4a bytes
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x3f bytes
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() + 0xf6 bytes
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state) + 0x28 bytes
    mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x43 bytes
    [Native to Managed Transition]
    [Managed to Native Transition]
    mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0xa7 bytes
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x92 bytes
    WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x48 bytes
    WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() + 0x110 bytes
    WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x6a bytes
    WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = 331926, int msg = 50025, System.IntPtr wParam = 0, System.IntPtr lParam = 0, ref bool handled = false) + 0x87 bytes
    WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x10f bytes
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback = {System.Windows.Threading.DispatcherOperationCallback}, object args = {Dimensions:[4]}, bool isSingleParameter = true) + 0x4a bytes
    WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, bool isSingleParameter, System.Delegate catchHandler = null) + 0x3f bytes
    WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, bool isSingleParameter) + 0x140 bytes
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority priority, System.Delegate method, object arg) + 0x3d bytes
    WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = 331926, int msg = 50025, System.IntPtr wParam = 0, System.IntPtr lParam = 0) + 0x196 bytes
    [Native to Managed Transition]
    [Managed to Native Transition]
    WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame}) + 0x147 bytes
    WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) + 0x83 bytes
    WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() + 0x75 bytes
    PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x83 bytes
    PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window) + 0x29 bytes
    PresentationFramework.dll!System.Windows.Application.Run() + 0x22 bytes
    ModelMagicUI.exe!ModelMagicUI.MyApp.Main() Line 59 + 0x9 bytes C#



  • Qwonfu

    Something is causing us to pump messages, but it is not clear from the stack:

    MS.Win32.HwndSubclass.SubclassWndProc
    [Native to Managed Transition] <-- We need to know what is going on in here...
    System.Windows.Markup.BamlRecordReader.ReadRecord

    If you could enable unmanaged debugging and get appropriate symbols that might help a lot. Or if you can send us a small repro I can dig this out for you.



  • Silvia Elena

    Exception means, we're in a place we don't support pumping messages (because we're in the middle of layout), yet somehow something is getting through to our WndProc. Why is a mystery to me, looking at the call stack I don't understand how we can get from BamlRecordReader.ReadRecord to a WndProc.

    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)

    Is there any way you can figure out what ReadRecord is doing when this hits Thanks.



  • Grahamrounce

    It is quite consistent in my application. I can not say exactly what part of the application is causing the issue. I change a property value and all kinds of elements and bindings fire. I expect that it is in changing the visuals related to one of the updated property values being rendered with a data template. Do you have any suggestions on how to narrow it down Is there any event I can register for that will indicate the template being applied, etc. Debugging the declaritive part of the framework is the biggest issue these days. When it works it is cool, but when it fails there is not that much to go on.

  • John7

    I have gotten the same Exception:
    In my case, it was caused by a TextBlock.IsVisibleChanged event, calling some code that pops up a SaveFileDialog. My guess is that the exception is related to threading, because the event thread calls into code in an object that is owned by another thread (in my case the window).
    Hope that this might help you figure out why it happens in the other program. I redesigned my app to prevent this from happening (the SaveFileDialog was not mission critical for this part of the program).

    Callstack:
    materialeditor.exe!materialeditor.Workspace.SaveDocument(Tools.MaterialEditorModel.MaterialDocument document = {Tools.MaterialEditorModel.MaterialDocument}) Line 154 C#

    materialeditor.exe!materialeditor.Workspace.SaveCurrentDocument() Line 186 + 0x16 bytes C#

    materialeditor.exe!materialeditor.Window1.PerformancePC_IsVisibleChanged(object sender = {System.Windows.Controls.TextBlock}, System.Windows.DependencyPropertyChangedEventArgs e = {System.Windows.DependencyPropertyChangedEventArgs}) Line 240 + 0x1f bytes C#

    [External Code]

    materialeditor.exe!materialeditor.MyApp.Run() Line 69 + 0x8 bytes C#

    [External Code]



  • Yunusov Bulat

    Does this problem repro consistently If so, can you attach the repro

    Thanks
    Derek


  • Hoot

    try:

    Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, del, args);

    and call RaiseEvent in the delegate.



  • Phillb

    Also note that this is a regression from Jan CTP if that helps. I never got enough running under the Feb CTP to know if it worked in that version.

  • Coolnet1savvy

    Could you look at the parameter to ReadRecord and find its RecordType field:

    internal virtual bool ReadRecord(BamlRecord bamlRecord)
    {
    ....

    switch (bamlRecord.RecordType)

    Knowing which case in the switch statement we're talking about could help a lot (it's a big switch statement!). Thanks.



  • New exception in Beta 2 makes no sense?