Debug.Assert Method (Boolean, String, String, Object())
Checks for a condition; if the condition is false, outputs two messages (simple and formatted) and displays a message box that shows the call stack.
Assembly: System (in System.dll)
<ConditionalAttribute("DEBUG")> Public Shared Sub Assert ( condition As Boolean, message As String, detailMessageFormat As String, ParamArray args As Object() )
The conditional expression to evaluate. If the condition is true, the specified messages are not sent and the message box is not displayed.
The composite format string (see Remarks) to send to the Listeners collection. This message contains text intermixed with zero or more format items, which correspond to objects in the args array.
An object array that contains zero or more objects to format.
This method uses the of the .NET Framework to convert the value of an object to its text representation and embed that representation in a string. The resulting string is sent to the Listeners collection.
Typically, the String.Format(String, Object()) method is called and the detailMessageFormat string and args array are passed in as parameters. then sends the specified text message and the formatted text message to the Listeners collection. You can customize this behavior by adding a TraceListener to, or removing one from, the Listeners collection.method is used to identify logic errors during program development. evaluates the condition. If the result is false, The
When the application runs in user interface mode, it displays a message box that shows the call stack with file and line numbers. The message box contains three buttons: Abort, Retry, and Ignore. Clicking the Abort button terminates the application. Clicking Retry sends you to the code in the debugger if your application is running in a debugger, or offers to open a debugger if it is not. Clicking Ignore continues with the next instruction in the code.
The display of the message box is dependent on the presence of the DefaultTraceListener. If the DefaultTraceListener is not in the Listeners collection, the message box is not displayed. The DefaultTraceListener can be removed by the <clear> Element for <listeners> for <trace>, the <remove> Element for <listeners> for <trace>, or by calling the Clear method on the Listeners property (System.Diagnostics.Trace.Listeners.Clear()).
You can change the behavior of the DefaultTraceListener in the configuration file that corresponds to the name of your application. In this file, you can enable and disable the assert message box or set the DefaultTraceListener.LogFileName property. The configuration file should be formatted as follows:
<configuration> <system.diagnostics> <assert assertuienabled="true" logfilename="c:\\myFile.log" /> </system.diagnostics> </configuration>
Available since 10
Available since 4.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0