I'm using a library which attempts to do Debug.Assert when I do a certio开发者_运维百科n thing, is there anyway to stop it from using Debug.Assert?
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.
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")]
)
Are you using a binary or do you have library source? In the former case, I suggest you contact your vendor to ask why they released a Debug build and also let them know about the Assert, which is a bug in their code (Assertion failures should never occur if code is executing as expected, even in exceptional cases.)
You can add the following section to your app.config
file which inhibits breaking on Debug.Assert(false)
:
<configuration>
<system.diagnostics>
<assert assertuienabled="false"/>
</system.diagnostics>
</configuration>
For details see assert
element and DefaultTraceListener.AssertUiEnabled Property.
精彩评论