Re: UTF8 exception in Nunit 2.4.8

William Garrison <[email protected]> Fri, 25 Jul 2008 12:06:32 -0400
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <[email protected]>
I realized I answered the environment question stupidly.  You didn't 
want the visual studio version.

OS Version: Microsoft Windows NT 5.1.2600 Service Pack 3
CLR Version: 2.0.50727.1433 ( Net 2.0.50727.1433 )

William Garrison wrote:
> Yes, it is definitely caused by Console.Out being "damaged" somehow.  
> It is definitely happening because of the refrence to Console.Out.
>
> - I have not run any of my tests prior to this point.  I was using the 
> /run command-line option, but if I remove that, this happens when I 
> click "run" on any of the tests.
> - I tried this against the samples and it is happening on those too :)
> - Environment:
> Visual Studio 2005 on Windows XP
> Version 8.0.50727.762 (SP.050727-7600)
> It should be using .NET 2.0.50727(I have 3.0 and 3.5 installed too)
>
> I bet that's it... I installed the Microsoft Platform SDK over the 
> weekend, and the last time I ran a unit test was just prior to that.
>
> Okay... so I removed all references to Console.Out and Console.Error 
> and Console.Write from the entire project, just to see if that fixed 
> it.  Now I get the exact same exception when nunit tries to create a 
> StreamWriter on line 27 of XmlResultVisitor.cs
>             xmlWriter = new XmlTextWriter( new StreamWriter(fileName, 
> false, System.Text.Encoding.UTF8) );
> I changed that to:
>             StreamWriter foo = new StreamWriter(fileName, false, 
> System.Text.Encoding.UTF8);
>             xmlWriter = new XmlTextWriter( foo );
> and it fails on the StreamWriter constructor:
>    at System.RuntimeMethodHandle.GetName()
>    at System.Reflection.RuntimeMethodInfo.get_Name()
>    at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
>    at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
>    at System.IO.StreamWriter.Init(Stream stream, Encoding encoding, 
> Int32 bufferSize)
>    at System.IO.StreamWriter..ctor(String path, Boolean append, 
> Encoding encoding, Int32 bufferSize)
>    at System.IO.StreamWriter..ctor(String path, Boolean append, 
> Encoding encoding)
>    at NUnit.Util.XmlResultVisitor..ctor(String fileName, TestResult 
> result) in 
> C:\svn\Scratch\wgarrison\NUnit-2.4.8-src\src\ClientUtilities\util\XmlResultVisitor.cs:line 
> 27
>    at NUnit.Util.TestLoader.SaveLastResult(String fileName) in 
> C:\svn\Scratch\wgarrison\NUnit-2.4.8-src\src\ClientUtilities\util\TestLoader.cs:line 
> 712
>    at 
> NUnit.Util.TestLoader.NUnit.Core.EventListener.RunFinished(TestResult 
> testResult) in 
> C:\svn\Scratch\wgarrison\NUnit-2.4.8-src\src\ClientUtilities\util\TestLoader.cs:line 
> 262
> (line numbers might be different due to me commenting-out sections)
>
> I am beginning to think this is a Microsoft problem... but I have 
> other apps that can construct streams and use console output just 
> fine.  So I'd like to dig some more to find out what nunit is doing 
> that might be triggering this.  In my original post, I highlight the 
> point at which console.out (and console.error too) "break" but I can't 
> see how or why it happens.  Any guesses as to what is happening in 
> step 2 (see original post) that would affect Console.Out?  I'm 
> wondering if it has something to do with remoting, because those 
> objects all derive from MarshalByRefObject and the 
> InitializeLifetimeService (which returns null) is called at that 
> point.  Why do these objects need to derive from that base class?  Why 
> override that method?  (Yes, I know that should have nothing to do 
> with Console output... it's just the only lead I can think of right now)
>
> Thanks for your help.
>
>
> Charlie Poole wrote:
>> In the very last lie of your stack trace, we can see that
>> NUnit is in the constructor of it's ContextHolder class.
>>
>> The ContextHolder is trying to save the value of Console.Out
>> so it can be restored later. An exception is being thrown,
>> within the .NET code. 
>>
>> Have any of your tests run before this point? That would
>> seem to be the only way that the value of Console.Out
>> could get messed up.
>>
>> Also, what's your environment?
>>
>> Charlie
>>
>>   
>>> -----Original Message-----
>>> From: [email protected] 
>>> [mailto:[email protected]] On Behalf 
>>> Of William Garrison
>>> Sent: Thursday, July 24, 2008 7:23 PM
>>> To: [email protected]
>>> Subject: [Nunit-users] UTF8 exception in Nunit 2.4.8
>>>
>>> I am trying to run NUnit GUI 2.4.8 on a DLL that I created and I get:
>>>    System.ArgumentException:   Message="The UTF8 string 
>>> passed in could 
>>> not be converted to Unicode."
>>>    at System.RuntimeMethodHandle.GetName()
>>>    at System.Reflection.RuntimeMethodInfo.get_Name()
>>>    at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
>>>    at System.Environment.GetStackTrace(Exception e, Boolean 
>>> needFileInfo)
>>>    at System.IO.StreamWriter.Init(Stream stream, Encoding encoding,
>>> Int32 bufferSize)
>>>    at System.IO.StreamWriter..ctor(Stream stream, Encoding encoding,
>>> Int32 bufferSize)
>>>    at System.IO.StreamWriter..ctor(Stream stream, Encoding encoding,
>>> Int32 bufferSize, Boolean closeable)
>>>    at System.Console.InitializeStdOutError(Boolean stdout)
>>>    at System.Console.get_Out()
>>>    at NUnit.Core.TestContext.ContextHolder..ctor() in 
>>> C:\svn\Scratch\wgarrison\NUnit-2.4.8-src\src\NUnitCore\core\Te
>>> stContext.cs:line
>>> 190
>>>
>>> I traced into the code far enough to know it has something to 
>>> do with the redirection of Console.Out.  But I'm not clear on 
>>> how that works or what is going wrong.
>>>
>>> I traced into the code, and here is what happens:
>>> 1) Set a breakpoint at line 147 of ProxyTestRunner.cs.  This line is:
>>>             this.testRunner.BeginRun( listener, filter ); At 
>>> this point, the value of Console.Out is valid.  I know that 
>>> seems irrelevent, but keep reading.  I then step into that call.
>>> 2) I am now at line 74 of RemoteTestRunner.cs.  That is the 
>>> first line of:
>>> public override void BeginRun( EventListener listener, 
>>> ITestFilter filter ) At this point, the value of Console.Out 
>>> results in the System.ArgumentException.  I do not understand 
>>> why Console.Out was destroyed at this point.
>>> 3) Now, run for a bit until line 190 of TestContext.cs.  That line is:
>>>                 this.outWriter = Console.Out; This is the 
>>> first reference to Console.Out since it was destroyed.  This 
>>> causes the exception.  It was a real bear to track down too, 
>>> because the debugger doesn't properly stop on exceptions that 
>>> are thrown from inside static constructors.  I had to turn on 
>>> native code debugging in Visual Studio to even see it
>>>
>>> I don't understand what Nunit is doing with Console.Out.  I 
>>> assume it is somehow redirecting it, and that is not working. 
>>>  But never in this process do I hit any line that does 
>>> Console.SetOut, so I don't see how that is it.  Can someone 
>>> explain how it is doing this?  Or what about it is causing 
>>> this crazy UTF8 exception?
>>>
>>>
>>>
>>> Lastly -- should I post this on the developer mailing list?
>>>
>>> --------------------------------------------------------------
>>> -----------
>>> This SF.Net email is sponsored by the Moblin Your Move 
>>> Developer's challenge Build the coolest Linux based 
>>> applications with Moblin SDK & win great prizes Grand prize 
>>> is a trip for two to an Open Source event anywhere in the 
>>> world http://moblin-contest.org/redirect.php?banner_id=100&url=/
>>> _______________________________________________
>>> Nunit-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/nunit-users
>>>
>>>     
>>
>>
>>
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
>> Build the coolest Linux based applications with Moblin SDK & win great prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> Nunit-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/nunit-users
>>
>>   
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users