I wrote a method Assert():
[System.Diagnostics.Conditional("DEBUG")]
internal static void Assert(bool condition)
{
if (!condition)
{
var message =
"Line:" + (new System.Diagnostics.StackFrame(1)).GetFileLineNumber() + "\r\n" +
"Column:" + (new System.Diagnostics.StackFrame(1)).GetFileColumnNumber() + "\r\n" +
"Where:" + (new System.Diagnostics.StackFrame(1)).GetMethod().Name;
Log("ASSERTION", message);
}
}
Why do I have both line and column being equal to 0, when triggered? It supposed to be the place where Debug.Assert(false) is called.
Regards,
You need to use the
StackFrame(int, bool)overload and specifytrueas the second argument. It looks like just theStackFrame(int)overload doesn’t capture source information.Sample code:
(Looking at your comments by the way, you will need the PDB files. That’s where the debug information is stored. It’s not at all clear to me whether this will work in a SQLCLR trigger, to be honest. The above works for me in a console app, but that’s all I can say…)