Debug.Fail (Suppressing Assert messagebox)

M

Mark W.B.

Hi all,
I have made a custom tracelistener that writes Debug trace messages to
an xml file.
I have added this new tracelistener with the following lines of code:

xmlListener = new XmlTraceListener("\\TestRunnerTrace.xml");
Debug.Listeners.Add(xmlListener);

The new TraceListener works fine, but I want to use this TraceListener
to test assertions and therefore need to suppress the Assert messagebox
for the DefaultTraceListener. According to the MSDN [1], this is done
by clearing the Debug.Listeners collection before adding the custom
TraceListener:

xmlListener = new XmlTraceListener("\\OMCETestRunnerTrace.xml");
Debug.Listeners.Clear();
Debug.Listeners.Add(xmlListener);

Unfortunately I cannot get this working as expected. The Assert
messagebox still pops up at my smartphone so I must be missing
something. Any ideas to what that might be?

I'm running .NET Compact Framework 2.0.

Thanks
Mark

[1] http://msdn2.microsoft.com/en-us/library/6z60kt1f.aspx (See Note)
 
S

Simon Hart

I have never had your requirement, but one thing springs to mind: Have you
tried overriding the Fail() methods in your XmlTraceListener class and do
not call the super class?

Simon.
 
M

Mark W.B.

Thank you for the reply Simon - this is how I override the Fail methods
of TraceListener:

public override void Fail(string message)
{
this.WriteXmlElement(message);
}

public override void Fail(string message, string detailMessage)
{
this.WriteXmlElement(message, detailMessage);
}

I'm not calling base, so its allright, is'nt it?
Anyway I don't think that the base of Fail pops up the Assert
messagebox. It must be some other TraceListener, which apparently does
not appear in the Debug.Listeners collection. By the way, its working
with the full .NET framework. Any other ideas?

Mark
 
S

Simon Hart

After you clear the Listeners collection, check that the Count is 0. This
will ensure the default listener is definitely removed.

Simon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top