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 Server crashing with CultureNotFoundException (en-us is an invalid culture identifier) #386

Closed
devrandomzero opened this issue Aug 13, 2023 · 19 comments · Fixed by dotnet/roslyn#70096
Assignees
Labels
area-extensionmanagement bug Something isn't working linux Linux triaged The issue has been triaged
Milestone

Comments

@devrandomzero
Copy link

Type: Bug

I'm using the new Unity extension with C# Dev Kit and as the title says the autocompletion doesn't work, I've tried to follow all the steps mentioned in this post and I think the problem is here:

3- Make sure C# Dev Kit is not displaying any error message

Here's the extension output:

Starting Open a solution...
Starting Open a solution with environment service...
Starting Clear environment...
Starting Spawn .NET server...
.NET server STDERR: Unhandled exception. 
.NET server STDERR: 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.GetCultureInfo(String name)
   at Microsoft.VisualStudio.Server.VSCodeCultureInheritance.InheritCultureFromVSCode()
   at Microsoft.VisualStudio.Server.ServiceBroker.Program.Main(String[] args)
   at Microsoft.VisualStudio.Server.ServiceBroker.Program.<Main>(String[] args)

.NET server STDOUT: [createdump] Gathering state for process 3223 Microsoft.Visua
[createdump] Crashing thread 0c97 signal 6 (0006)

.NET server STDOUT: [createdump] Writing crash report to file /tmp/csdevkit/dumps/Microsoft.Visua.3223.dmp.crashreport.json

.NET server STDOUT: [createdump] Crash report successfully written

.NET server STDOUT: [createdump] Writing minidump with heap to file /tmp/csdevkit/dumps/Microsoft.Visua.3223.dmp

.NET server STDOUT: [createdump] Written 68587520 bytes (16745 pages) to core file

.NET server STDOUT: [createdump] Target process is alive

.NET server STDOUT: [createdump] Dump successfully written in 1814ms

.NET server exited with null

Thanks

Extension version: 0.4.2
VS Code version: Code 1.81.1 (6c3e3dba23e8fadc360aed75ce363ba185c49794, 2023-08-09T22:18:39.991Z)
OS version: Linux x64 6.4.9-arch1-1
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz (8 x 3746)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 1, 1, 0
Memory (System) 15.58GB (11.96GB free)
Process Argv --unity-launch --crash-reporter-id c1843333-17d3-4f26-9a41-9d22f34a22f9
Screen Reader no
VM 0%
DESKTOP_SESSION plasma
XDG_CURRENT_DESKTOP KDE
XDG_SESSION_DESKTOP KDE
XDG_SESSION_TYPE x11
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
vsccc:30803844
282f8724:30602487
89544117:30613380
showlangstatbar:30737416
03d35959:30757346
pythonfmttext:30731395
pythoncmv:30756943
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
gsofa:30804715
pythonnosmt12:30797651
pythonidxpt:30805730
pythonnoceb:30805159
synctok:30810529
dsvsc013:30795093
dsvsc014:30804076

@microsoft-issue-labeler microsoft-issue-labeler bot added the area-templates Experiences around the project/item templates label Aug 13, 2023
@sailro sailro added area-roslyn and removed area-templates Experiences around the project/item templates labels Aug 13, 2023
@sailro sailro changed the title Autocompletion in Unity doesn't work .NET Server crashing with CultureNotFoundException (en-us is an invalid culture identifier) Aug 13, 2023
@sailro sailro added bug Something isn't working area-other Larger bucket for 'other' functional areas and removed area-roslyn labels Aug 13, 2023
@sailro
Copy link
Member

sailro commented Aug 13, 2023

cc @jbevain

In this case, it is not related to our Unity extension.

The .NET server part is crashing getting CultureInfo.GetCultureInfo(locale) with a en-us locale, coming from VSCODE_NLS_CONFIG

@devrandomzero could you share your locale settings in VSCode, but also for your system-OS (like what are the regions/languages supported). Thank you!

It seems the associated runtime is running in invariant mode in this case : https://aka.ms/GlobalizationInvariantMode

@devrandomzero
Copy link
Author

cc @jbevain

In this case, it is not related to our Unity extension.

The .NET server part is crashing getting CultureInfo.GetCultureInfo(locale) with a en-us locale, coming from VSCODE_NLS_CONFIG

@devrandomzero could you share your locale settings in VSCode, but also for your system-OS (like what are the regions/languages supported). Thank you!

It seems the associated runtime is running in invariant mode in this case : https://aka.ms/GlobalizationInvariantMode

Thank you @sailro, here's my system locale:

LC_CTYPE=en_US.utf8
LC_NUMERIC=it_IT.utf8
LC_TIME=it_IT.utf8
LC_COLLATE="it_IT.UTF-8"
LC_MONETARY=it_IT.utf8
LC_MESSAGES=en_US.utf8
LC_PAPER=it_IT.utf8
LC_NAME="it_IT.UTF-8"
LC_ADDRESS="it_IT.UTF-8"
LC_TELEPHONE="it_IT.UTF-8"
LC_MEASUREMENT=it_IT.utf8
LC_IDENTIFICATION="it_IT.UTF-8"
LC_ALL=

VSCode
image

Hope is enough
Thanks

@sean-jost
Copy link

I have the same issue except I am not using Unity. I am using Remote-SSH to a RHEL 7.9 machine. When the C# DevKit extension activates, I get the exact same error. We are using Invariant mode for globalization, i.e. DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1.

@sailro
Copy link
Member

sailro commented Aug 15, 2023

I have the same issue except I am not using Unity. I am using Remote-SSH to a RHEL 7.9 machine. When the C# DevKit extension activates, I get the exact same error. We are using Invariant mode for globalization, i.e. DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1.

Yes I think that is the root issue, the C# Dev Kit server-part should handle that the associated runtime is setup for invariant culture, providing at least a fallback to a default culture when hitting such a CultureNotFoundException.

It seems there is not current API for detecting this invariant mode:
https://stackoverflow.com/questions/75298957/how-to-detect-globalization-invariant-mode

But an API proposal was submitted:
dotnet/runtime#81429

cc @AArnott for awareness.

@webreidi webreidi added this to the GA milestone Aug 15, 2023
@webreidi webreidi added the linux Linux label Aug 16, 2023
@AArnott AArnott self-assigned this Aug 17, 2023
@AArnott
Copy link
Member

AArnott commented Aug 17, 2023

What is the purpose for setting DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1? Would it defeat the purpose if we cleared that environment variable when spawning the .NET server process?

@AArnott AArnott added triaged The issue has been triaged area-extensionmanagement and removed area-other Larger bucket for 'other' functional areas labels Aug 17, 2023
@sailro
Copy link
Member

sailro commented Aug 18, 2023

What is the purpose for setting DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1? Would it defeat the purpose if we cleared that environment variable when spawning the .NET server process?

From what I understand, specific Linux distributions are made to be super small like Alpine, without ICU installed by default and .NET requires icu-libs for globalization support.

That's why this flag was introduced to allow the .NET runtime to work on those systems knowing the drawback will be poor globalization support.

Microsoft is even offering Docker files for .NET/Alpine with this flag explicitly set:
https://github.com/dotnet/dotnet-docker/blob/main/src/aspnet/7.0/alpine3.18/amd64/Dockerfile#L4

So clearing DOTNET_SYSTEM_GLOBALIZATION_INVARIANT before spawning will change nothing, we probably do not have support for globalization at the os-level anyway.

@devrandomzero @sean-jost do you have a similar use case ?

@AArnott
Copy link
Member

AArnott commented Aug 18, 2023

Thanks. The next prerelease will swallow this exception.

@sean-jost
Copy link

sean-jost commented Aug 18, 2023

@sailro It is very strange because when I query locale settings via localectl status it shows me en_US.UTF-8, and when simply ssh to the server via command line I have DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=0, but when I use remote-ssh extension in VS Code it is set to 1. Even with no other extensions in use.

@devrandomzero
Copy link
Author

@sailro I've also tried to set in my env DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=0 but the problem persists.

@AArnott
Copy link
Member

AArnott commented Aug 21, 2023

The next prerelease

... or maybe next week's. We're having some trouble with some other changes and they may cause this fix to not quite make this week's release.

@devrandomzero
Copy link
Author

Hi, any news about this?

Thank you

@sailro
Copy link
Member

sailro commented Sep 12, 2023

Hi, any news about this?

Thank you

It should be released, make sure you are using pre-releases (go to Extensions, C# Dev Kit and click Switch to Pre-Release version)

@devrandomzero
Copy link
Author

Hi,
I'm still getting errors, when starting vscode I get this message in the console:

[Info - 6:55:08 PM] [Program] Language server initialized [Warn - 6:55:08 PM] [LanguageServerHost] Culture en was not found, falling back to OS culture

Then sometimes when I try to use the autocomplete function I get this error
[Error - 6:55:33 PM] [LanguageServerHost] System.TypeInitializationException: The type initializer for 'Microsoft.CodeAnalysis.Completion.PatternMatchHelper' threw an 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.

and a popup in the bottom right corner with this message

Request textDocument/completion failed.

VS Code = v1.82.2-1
C# Dev Kit = v0.5.98
IntelliCode for C# Dev Kit = v0.1.26

Thank you for your help

@sailro
Copy link
Member

sailro commented Sep 22, 2023

Indeed, it seems it was correctly fixed in C# Dev Kit by @AArnott (we just have a warning to track that a specific culture was not found).

But this line is wrong in Roslyn in the context of GlobalizationInvariantMode :
https://github.com/dotnet/roslyn/blob/main/src/Features/Core/Portable/Completion/PatternMatchHelper.cs#L24

cc @CyrusNajmabadi and @genlu, for more context see #386 (comment)

cc @jbevain

@CyrusNajmabadi
Copy link

What is the right way to get the english culture (or some reasonable fallback culture) in that case?

@AArnott
Copy link
Member

AArnott commented Sep 23, 2023

@CyrusNajmabadi I think all you have is Invariant, which uses the neutral culture for your assembly.

@CyrusNajmabadi
Copy link

CyrusNajmabadi commented Sep 23, 2023 via email

@sailro
Copy link
Member

sailro commented Sep 23, 2023

@CyrusNajmabadi check this comment #386 (comment)

@CyrusNajmabadi
Copy link

Ok. Opened dotnet/roslyn#70096 as the poor-man's way of handling this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-extensionmanagement bug Something isn't working linux Linux triaged The issue has been triaged
Projects
None yet
6 participants