Skip to content

debug-assert-message

C#styleno fixdefault: offcsharp/stylecop

Reports a Debug.Assert call without a message, or with a message that is a constant blank string. With the type layer the call is checked against System.Diagnostics.Debug; without it any call written Debug.Assert is. No fix.

When an assertion fails in a debug build the message is all that is shown. Without it the developer has the line number and the condition, and a long sequence of asserts in a function does not tell which one broke or why it matters.

To fix, add a message that says what is wrong when the condition is false.

Reported
...
Debug.Assert(true);
Debug.Assert(true, "why");
...
}
...
After the fix
...
Debug.Assert(true);
Debug.Assert(true, "why");
...
}
...
csharp:
lint:
rules:
debug-assert-message: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line debug-assert-message in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1405 full