This situation occurs because when MSTest redirects the console output to the test window, it passes CultureInfo.InvariantCulture to the TextWriter associated with the console.
You can check this with the following:
var threadCulture = Thread.CurrentThread.CurrentCulture; var consoleCulture = Console.Out.FormatProvider; Console.WriteLine(threadCulture.Equals(CultureInfo.InvariantCulture)); Console.WriteLine(consoleCulture.Equals(CultureInfo.InvariantCulture));
If you do not change it, the current thread culture is usually en-US or regardless of your computer. Therefore, the first element will usually be false.
But the second element changes depending on where it works from. As a console application, the console output culture should default to the current thread culture, so it will be false. In XUnit or NUnit tests, the result is also incorrect. But in MSTest the result is correct.
If you dig up . The reference source of the .NET Framework , you will see that
I do not think that the sources for the MSTest tester are publicly available, but we can conclude that they should do something like this somewhere:
Console.Out = new SomeWriter(CultureInfo.InvariantCulture);
Where SomeWriter generates test output and inherits from TextWriter .
String.Format , String.Format other hand, String.Format always use the current thread culture, unless you specifically provide another culture.
One way around this would be to explicitly link the current flow culture to the invariant culture.
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;