Break the debugger on assertion failed

2020-07-02 12:00发布

Is there a way to break the debugger when assertion is false and running the application using Visual Studio debugger. Earlier when I was debugging Windows application I would get an exception and the debugger would break, but now on Smart Device an assertion failed window is showed with stack trace, but I would also like to see variable values etc.

4条回答
爷、活的狠高调
2楼-- · 2020-07-02 12:13

It seems that you can attach the Debugger when assertion fails to see other details - see this article: http://blogs.msdn.com/b/davidklinems/archive/2005/08/29/457847.aspx. Its quite dated but perhaps still applicable.

查看更多
【Aperson】
3楼-- · 2020-07-02 12:14

Stupid me, the solution was simple. When the window pops out, press pause in debugger :)

查看更多
别忘想泡老子
4楼-- · 2020-07-02 12:14

In addition to Vinay's solution, you can start the debugger for a specific process by calling

Debugger.Break

In your case you could do it every time the listener receives a failure message.

查看更多
三岁会撩人
5楼-- · 2020-07-02 12:29

Not sure about VS 2008, but in at least 2010 and later, you can go to Debug/Exceptions (Ctrl-Alt-E). Click the "Add" button, choose "Common Language Runtime Exceptions", and type:

Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException

and hit "OK". It will now appear on the list, make sure you check the checkbox in the "Thrown" column. You will now get a break on any assert failure.

Updated: screenshot from VS 2017 AssertFailedException

查看更多
登录 后发表回答