Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Debug.Assert?

Tags:

c#

debugging

I'm using a library which attempts to do Debug.Assert when I do a certion thing, is there anyway to stop it from using Debug.Assert?

like image 236
Levi H Avatar asked May 23 '11 19:05

Levi H


People also ask

How do I turn off asserts?

Disable assert in C++ One way to disable the assertions is by searching for the assert macro in code after the debugging is completed and removing it manually. A better approach is to disable it using the NDEBUG macro.

How do I disable assert in Visual Studio?

In Visual Studio, go to Debug / Windows / Exception Settings. In the Exception Settings, go to Win32 Exceptions / 0xc0000420 Assertion Failed. Uncheck the box in front of that entry.

What is debug assert?

Assert(Boolean) Checks for a condition; if the condition is false , displays a message box that shows the call stack. Assert(Boolean, Debug+AssertInterpolatedStringHandler) Checks for a condition; if the condition is false , outputs a specified message and displays a message box that shows the call stack.

What is debug assert in VBA?

The Assert method is available only in Visual Basic; the Debug object in the VBA development environment doesn't support the Assert method. Assert is typically used when debugging to test an expression that should evaluate to True. If it doesn't, the Immediate window can be used to investigate why the test failed.


2 Answers

If you can recompile the library, then Marc is correct; just recompile it without DEBUG defined and all the assertions will disappear.

If you can't do that, because say you don't have the source code of the library, then you can have your program clear out the Trace Listeners. That way when the assertion fires, it still fires but it does nothing. (When an assertion fires, it just checks to see what trace listeners are registered, and informs them about the assertion. No listeners means nothing happens.)

In that scenario you might consider replacing the default trace listener with a customer trace listener of your own that does something like logs the assertion to a file. That way you can review the log and see what assertions would have popped up in the "normal" execution of the debug version of the library.

like image 200
Eric Lippert Avatar answered Oct 19 '22 06:10

Eric Lippert


If you compile it without the DEBUG symbol defined, then no calls to Debug.Assert will be compiled (the methods are defined with [Conditional("DEBUG")])

like image 43
Marc Gravell Avatar answered Oct 19 '22 08:10

Marc Gravell