logging - Object Disposed Exception when using .Net Trace Source within VS UNit Tests -
When I tried to call TraceSource.TraceData with your VS2008 unit test project, so I got the object Exception Exception Used to be. I have included a very small code sample below, which repeatedly issues this issue. I'm seeing this after running my first unit test - but in my journey it will increase once on my website and affect me if I run with many users.
This is like the underlying stream, after the first unit test, the 'overflow' gurus can be greatly assisted by the closed ones.
Step:
1) VS Make 2008 Unit Test Project
2) Add a class with this code:
Namespace Tracing Error {Using System.Diagnostics; Use of Microsoft Visual Studio Test Tools Unitatistics; [Test class] public class unit 1 {public status traceSource ts = new trace source ("trace test"); [TestMethod] Public Zero A () {ts.TraceEvent (TraceEventType.Information, 1, "Hello AA"); } [TestMethod] Public Zero (B) {ts.TraceEvent (TraceEventType.Information, 1, "Hello from B"); }}}
3) Add an app.config to this code:
& Lt; Remove name = "default" /> & Lt; / Listeners & gt; & Lt; / Source & gt; & Lt; / Sources & gt; & Lt; Switch & gt; & Lt; Add name = "SourceSwitch" value = "Verbose" /> & Lt; / Switch & gt; & Lt; Trace autoflush = "true" indentsize = "4" & gt; & Lt; / Trace & gt; & Lt; /system.diagnostics> & Lt; / Configuration & gt;
The same problem I run tests using code with the trace Had to face. WriteLine call is running a single test, but many later was triggered following call stack:
System.IO .__ Trutikvidhiclad () System.IO.StringWriter.Write ( char [] buffer, Int32 index, Int32 count) SystemkDiagnostics SystemkIOkTextWriterkWriteLine (string) System.IO.TextWriter.SyncTextWriter.WriteLine (string value) System.Diagnostics.TextWriterTraceListener.WriteLine (string message). TraceInternal.WriteLine (string message) System.Diagnostics.Trace.WriteLine (string message)
some investigation I found the following in your test setup After solving the problem by placing the code:
[Test Initiative ()] Public Zero Setup () (Array.ForH (trace in trace listener TL.Listener where tl.Name! = Select "Default" tl) .Oir (), TL => Trace.List. Remove (TL)); }
Obviously, when running in the mstest environment, there is a problem with multiple trace listeners MSTEST is adding a system. Diagnostics TextViratorress Listener is using a stream that is dealt with after the first test. The solution alternatively removes all trace listeners, effectively removing the mstest-added listener. The problem is linked to some unfair handling of trace stream created by MSEST. First I said that mstest created an AppDomain for each test. it is not true.
I see that you filed a bug report with Microsoft, but did not get any useful feedback. Hope this quick correction will work for you, as it did for me.
Comments
Post a Comment