[Mono-dev] System.Diagnostics.Process behaves differently in and outside of a NUnit test case

Dan Liew dan at su-root.co.uk
Fri Oct 9 13:40:14 UTC 2015


Hi,

This is an issue that I was bitten by a while ago but I didn't post
here because I managed to work around it but it looks like something
inside mono changed between 3.12 and 4.0.4 which my broke my
workaround.

The issue basically is I observed my code failing when called from an
NUnit test but when run from an executable it would work fine. The
code in question [1] calls out to an external process using
``System.Diagnostics.Process`` where the standard input is redirected.
When running from an NUnit test a UTF-8 BOM gets sent to the process's
standard input and when running from an executable the UTF-8 BOM does
not get sent.

I looked at this again and I've noticed two things

* In System.Diagnostics.Process.Start_noshell() the encoding for the
writable end of the pipe connected to the child process's standard
input is taken from ``Console.Out.Encoding``. Is this really a good
idea? Depending on this global value seems like a bad idea and could
introduce weird race conditions if the Console.Out encoding is changed
in some way (e.g. ``Console.OutputEncoding = new
System.Text.UTF8Encoding(false);`` seems to do this and this the new
workaround I ended up using)

* When running in an executable the value of
``Console.Out.Encoding.emitUTF8Identifier`` is false but when running
in an NUnit test the value of
````Console.Out.Encoding.emitUTF8Identifier`` is true!
I'm not sure if this is Mono's or NUnit's fault but this seems very wrong to me.

I've filled a bug at [2] and [3] but thought I'd post about it here
too as this issue seems partially tied to some of mono's internal
implementation details.

[1] https://bugzilla.xamarin.com/attachment.cgi?id=13247
[2] https://bugzilla.xamarin.com/show_bug.cgi?id=21374
[3] https://github.com/nunit/nunit/issues/881

Thanks,
Dan.


More information about the Mono-devel-list mailing list