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

.NET 6.0.6: DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 doesn't work any more #7747

Closed
ww898 opened this issue Jun 27, 2022 · 8 comments
Closed
Assignees
Labels

Comments

@ww898
Copy link

ww898 commented Jun 27, 2022

Windows x64 .NET SDK 6.0.301. Languages: en-us, de-de, ru-ru. DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 doesn't work any more.

sample.cmd:

set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
dotnet new console

Console output:

> dotnet new console
The template "Console App" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on C:\Work\__\__.csproj...
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-US is an invalid culture identifier.
   at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride)
   at System.Globalization.CultureInfo..ctor(String name)
   at Microsoft.Build.CommandLine.MSBuildApp.SetConsoleUI()
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
Unhandled exception: System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-US is an invalid culture identifier.
   at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride)
   at System.Globalization.CultureInfo..ctor(String name)
   at Microsoft.Build.CommandLine.MSBuildApp.SetConsoleUI()
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
   at Microsoft.Build.CommandLine.MSBuildApp.Main(String[] args)
   at Microsoft.DotNet.Cli.Utils.MSBuildForwardingAppWithoutLogging.ExecuteInProc(String[] arguments)
Restore failed.
Post action failed.
@rainersigwald
Copy link
Member

I do not repro with that SDK:

> set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true

> del inv.csproj Program.cs

> dotnet new console
The template "Console App" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on S:\play\inv\inv.csproj...
  Determining projects to restore...
  All projects are up-to-date for restore.
Restore succeeded.



> dotnet --version
6.0.301

Are you seeing this consistently? Does this only happen if the primary OS language is non-US-English?

@rainersigwald rainersigwald added the needs-more-info Issues that need more info to continue investigation. label Jul 7, 2022
@ghost ghost removed the needs-triage Have yet to determine what bucket this goes in. label Jul 7, 2022
@ghost ghost added the stale For issues that haven't had activity in some time. label Aug 7, 2022
@ghost
Copy link

ghost commented Aug 7, 2022

This issue is marked as stale because feedback has been requested for 30 days with no response. Please respond within 14 days or this issue will be closed due to inactivity.

@ghost ghost closed this as completed Aug 21, 2022
@ghost
Copy link

ghost commented Aug 21, 2022

This issue was closed due to inactivity. If you can still reproduce this bug, please comment with the requested information, detailed steps to reproduce the problem, or any other notes that might help in the investigation.

@ghost ghost added the closed-by-bot Closed due to lack of activity label Aug 21, 2022
@asmichi
Copy link

asmichi commented Oct 9, 2022

Stumbled upon this issue while investigating how to work around the MSBuild slowdown caused by dotnet/runtime#31273. (I guess DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY=0 (if combined with chcp 65001) should be relatively safer in this specific case, though.)

Does this only happen if the primary OS language is non-US-English?

Seemingly yes. Specifically, the difference is the codepage. Codepage 932 (Shift JIS, Japanese) reproduces the issue. 437 (OEM US) and 65001 (UTF-8) are fine.

Repro:

chcp 932
dotnet new console
set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
dotnet build
chcp 437
dotnet build
D:\home\tmp\ConsoleApp>chcp 932
現在のコード ページ: 932

D:\home\tmp\ConsoleApp>dotnet new console
テンプレート "コンソール アプリ" が正常に作成されました。

作成後の操作を処理しています...
D:\home\tmp\ConsoleApp\ConsoleApp.csproj で ' dotnet restore ' を実行しています...
  復元対象のプロジェクトを決定しています...
  復元対象のすべてのプロジェクトは最新です。
正常に復元されました。



D:\home\tmp\ConsoleApp>set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1

D:\home\tmp\ConsoleApp>dotnet build
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-US is an invalid culture identifier.
   at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride)
   at System.Globalization.CultureInfo..ctor(String name)
   at Microsoft.Build.CommandLine.MSBuildApp.SetConsoleUI()
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
Unhandled exception: System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-US is an invalid culture identifier.
   at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride)
   at System.Globalization.CultureInfo..ctor(String name)
   at Microsoft.Build.CommandLine.MSBuildApp.SetConsoleUI()
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
   at Microsoft.Build.CommandLine.MSBuildApp.Main(String[] args)
   at Microsoft.DotNet.Cli.Utils.MSBuildForwardingAppWithoutLogging.ExecuteInProc(String[] arguments)

D:\home\tmp\ConsoleApp>chcp 437
Active code page: 437

D:\home\tmp\ConsoleApp>dotnet build
MSBuild version 17.3.1+2badb37d1 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  ConsoleApp -> D:\home\tmp\ConsoleApp\bin\Debug\net6.0\ConsoleApp.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.67

@ghost ghost added the needs-triage Have yet to determine what bucket this goes in. label Oct 9, 2022
@asmichi
Copy link

asmichi commented Oct 9, 2022

I guess the exception is raised here (new CultureInfo("en-US")):

msbuild/src/MSBuild/XMake.cs

Lines 1478 to 1488 in 2badb37

if (
codepage != 65001 // 65001 is Unicode
&&
codepage != thisThread.CurrentUICulture.TextInfo.OEMCodePage
&&
codepage != thisThread.CurrentUICulture.TextInfo.ANSICodePage
)
{
thisThread.CurrentUICulture = new CultureInfo("en-US");
return;
}

(In .NET 6)
In the globalization invariant mode CurrentUICulture and CultureInfo.CurrentUICulture.GetConsoleFallbackUICulture() are the invariant culture. CurrentUICulture.TextInfo.OEMCodePage and CurrentUICulture.TextInfo.ANSICodePage are 437 and 1252 respectively. Therefore 65001, 437 and 1252 are fine while others fail.

@rainersigwald
Copy link
Member

The bot didn't reactivate after @asmichi's comments and we missed this, sorry.

@rainersigwald rainersigwald reopened this Jul 21, 2023
@ghost ghost removed the stale For issues that haven't had activity in some time. label Jul 21, 2023
@rainersigwald rainersigwald added Localization and removed needs-more-info Issues that need more info to continue investigation. closed-by-bot Closed due to lack of activity labels Jul 21, 2023
@maridematte maridematte added triaged Priority:3 Work that is nice to have and removed needs-triage Have yet to determine what bucket this goes in. labels Oct 15, 2024
@GangWang01 GangWang01 self-assigned this Oct 17, 2024
@GangWang01
Copy link
Member

As @asmichi pointed out above, if DOTNET_SYSTEM_GLOBALIZATION_INVARIANT is enabled and code page meets the conditions, msbuild will crash attempting to create CultureInfo new CultureInfo("en-US"). This was fixed in main branch by #8738.

For .NET 6 (currently latest version is 6.0.427), it till has this issue. Considering it's approaching the end of support very soon, it will probably be not fixed in .NET 6.

@GangWang01
Copy link
Member

Close as it's out of support now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants