Debug.Assert() cannot popup a dialog in Visual Studio in the WPF project - by Bob_Bao

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


9
0
Sign in
to vote
ID 687333 Comments
Status Closed Workarounds
Type Bug Repros 8
Opened 9/5/2011 8:20:31 PM
Access Restriction Public

Description

A simple WPF application with one button, in the button click event, we add the code:
System.Diagnostics.Debug.Assert(false);  

When we click the button, it cannot popup the assert dialog, just output the call stack inthe output panel of the Visual Studio 2010.

If we enable the function "Enable Just My Code", it can popup up the dialog. And test in the VS 2008, it can show the dialog always. So I think it is an issue of VS 2010. 
Sign in to post a comment.
Posted by marcinwis on 3/30/2012 at 1:46 AM
Workaround sometimes does not work. For example when debug failure happens in MarkupExtension, InvalidOperationException is thrown with message "Dispatcher processing has been suspended, but messages are still being processed." and stacktrace:

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, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at Microsoft.Win32.SafeNativeMethods.MessageBox(IntPtr hWnd, String text, String caption, Int32 type)
at System.Diagnostics.AssertWrapper.ShowMessageBoxAssert(String stackTrace, String message, String detailMessage)
at System.Diagnostics.DefaultTraceListener.Fail(String message, String detailMessage)
at System.Diagnostics.DefaultTraceListener.Fail(String message)
at System.Diagnostics.TraceInternal.Fail(String message)
at System.Diagnostics.Debug.Fail(String message)
at XXXExtension.ProvideValue(IServiceProvider serviceProvider) in C:\XXXExtension.cs:line 76
at System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
at System.Windows.StyleHelper.GetChildValueHelper(UncommonField`1 dataField, ItemStructList`1& valueLookupList, DependencyProperty dp, DependencyObject container, FrameworkObject child, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.GetChildValue(UncommonField`1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.GetValueFromTemplatedParent(DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, FrameworkElementFactory templateRoot, EffectiveValueEntry& entry)
at System.Windows.StyleHelper.ApplyTemplatedParentValue(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, DependencyProperty dp, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
at System.Windows.FrameworkTemplate.InvalidatePropertiesOnTemplate(DependencyObject container, Object currentObject)
at System.Windows.FrameworkTemplate.HandleBeforeProperties(Object createdObject, DependencyObject& rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
at System.Windows.FrameworkTemplate.<>c__DisplayClass6.<LoadOptimizedTemplateContent>b__3(Object sender, XamlObjectEventArgs args)
at System.Xaml.XamlObjectWriter.OnBeforeProperties(Object value)
at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
Posted by Dwayne [MSFT] on 9/22/2011 at 4:31 PM
This is not a WPF issue, but rather an issue with VS. It seems that a debugging component is configuring the trace listeners such that they do not display UI under these circumstances for failing Asserts. The good news is that this appears to have been fixed in the next version of Visual Studio.

Posted by marsovo on 9/13/2011 at 8:01 PM
This happens to me as well, inconsistently. It happens whether the assert comes from the main thread or a background thread. I am using VS Express.
Posted by EricLeong [Feedback Moderator] on 9/6/2011 at 8:09 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Vic Klien on 9/5/2011 at 8:59 PM
Expanding a little on Bob's description:

When a .NET program, running under the VS debugger, calls Debug.Assert( false ) three things should happen:

1) A "DEBUG ASSERTION FAILED" message should be shown in the VS output window.
2) An "Assertion Failed" dialog should be displayed.
3) If the "Retry" button of the dialog is pressed, the VS debugger should
pause the program and highlight the source line containing the Assert.


The problem is that when VS2010 or VS2010+SP1 debug a WPF program, #2 and #3 don't happen.

If VS2010 or VS2010+SP1 debug a WinForms program, all 3 happen correctly.
If VS2008 debugs a WPF program, all 3 happen correctly.


I reproduced this problem on both XP-SP3-32bit and on WSrv2k8R2-64bit OSes.

Vic
Posted by MS-Moderator01 on 9/5/2011 at 8:41 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)