Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in DOTNET_SYSTEM_GLOBALIZATION_INVARIANT mode #8738

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/MSBuild.UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,30 @@ public void SetConsoleUICulture()
thisThread.CurrentUICulture = originalUICulture;
}

/// <summary>
/// We shouldn't change the UI culture if the current UI culture is invariant.
/// In other cases, we can get an exception on CultureInfo creation when System.Globalization.Invariant enabled.
/// </summary>

[Fact]
public void SetConsoleUICultureInInvariantCulture()
{
Thread thisThread = Thread.CurrentThread;

// Save the current UI culture, so we can restore it at the end of this unit test.
CultureInfo originalUICulture = thisThread.CurrentUICulture;

thisThread.CurrentUICulture = CultureInfo.InvariantCulture;
MSBuildApp.SetConsoleUI();

// Make sure we don't change culture.
thisThread.CurrentUICulture.ShouldBe(CultureInfo.InvariantCulture);

// Restore the current UI culture back to the way it was at the beginning of this unit test.
thisThread.CurrentUICulture = originalUICulture;
}


#if FEATURE_SYSTEM_CONFIGURATION
/// <summary>
/// Invalid configuration file should not dump stack.
Expand Down
3 changes: 2 additions & 1 deletion src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,8 @@ internal static void SetConsoleUI()
&&
codepage != thisThread.CurrentUICulture.TextInfo.OEMCodePage
&&
codepage != thisThread.CurrentUICulture.TextInfo.ANSICodePage)
codepage != thisThread.CurrentUICulture.TextInfo.ANSICodePage
&& !Equals(CultureInfo.InvariantCulture, thisThread.CurrentUICulture))
{
thisThread.CurrentUICulture = new CultureInfo("en-US");
return;
Expand Down