Debug.Assert () only works when going through it

I am using Visual Studio 2010 to write a .NET statement:

Debug.Assert(false, "Testing Debug.Assert"); 

When I put a breakpoint on this line of code, wait until the breakpoint hits, and then let the program continue to work, everything will be fine: the "Assertion Failed" dialog box appears. However, when I remove the breakpoint and restart the application, the Debug.Assert () expression is simply ignored.

Does anyone have an idea what might cause this very weird behavior?

+6
source share
3 answers

My colleague immediately realized what the problem was. I had to enable the "Include only my code" flag in "Visual Studio 2010 / Menu / Options / Debugging / General". This seems to be a bug in Visual Studio 2010 .

+3
source

I had the same problem. Using Trace.Assert works as expected.


So, Trace.Assert began to exhibit the same behavior in the next debugging session.


Ah, I found a problem.

  • Check the box "Include only my code."

    • If "Thrown" is checked for "General runtime language exceptions" in the "Exceptions" dialog box (Ctrl + Alt + E), Assert will be issued.

    • If unchecked, Assert will be displayed.

  • With "Enable only my code" disabled.

    • If the checkbox is “unchecked”, a confirmation will not be selected.

    • If Abandoned is not installed, Assert will appear.

Consequently, Assert will not be thrown if the “Include only my code” checkbox is not selected, and “Abandoned” is checked for “Exclude the total runtime of the language”.

+2
source

The answers given here did not help, but I found out that it was as simple as checking the "Define DEBUG constant" parameter for the Debug configuration in the project build settings:

The Define DEBUG constant option in project's build settings

0
source

Source: https://habr.com/ru/post/899777/


All Articles