msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

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

Open ww898 opened this issue 2 years ago • 2 comments

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.

ww898 avatar Jun 27 '22 14:06 ww898

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 avatar Jul 07 '22 16:07 rainersigwald

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 avatar Aug 07 '22 00:08 ghost

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 avatar Aug 21 '22 19:08 ghost

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

asmichi avatar Oct 09 '22 09:10 asmichi

I guess the exception is raised here (new CultureInfo("en-US")): https://github.com/dotnet/msbuild/blob/2badb37d109910fbd3155cf8743224b7a27494d8/src/MSBuild/XMake.cs#L1478-L1488

(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.

asmichi avatar Oct 09 '22 09:10 asmichi

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

rainersigwald avatar Jul 21 '23 14:07 rainersigwald