Is there a strict rule that Debug.Assert should be used only for checking members of a class or used to check parameters to a public method?
Do not use Debug.Assert()
to check parameters to a public method. Parameters should be checked in both debug and release builds.
You should use an explicit if
followed by thowing ArgumentNullException
, ArgumentOutOfRangeException
or ArgumentException
for invalid parameters.
Alternatively, use Code Contracts
to express the parameter preconditions using Contract.Requires()
.
For further reference, see this thread: When should I use Debug.Assert()?
Other than that, then you can use Debug.Assert()
wherever you want, but be aware that it might take a little more setting up for Asp.Net: Is it worth using Debug.Assert in ASP.NET?
Also see here: http://gregbeech.com/blog/how-to-integrate-debug-assert-with-your-asp-net-web-application