You can add a custom TraceListener that throws an exception in any of the .Fail() methods:
public class ThrowListener : TextWriterTraceListener { public override void Fail(string message) { throw new Exception(message); } public override void Fail(string message, string detailMessage) { throw new Exception(message); } }
I would probably get my own Exception type, which accepts both the message and detailMessage, and so it becomes more obvious where the exception comes from.
You will need to expand the call stack before calling .Assert (), since the debugger will most likely lead you to throw .
You can add it like this:
Debug.Listeners.Insert(0, new ThrowListener());
source share