From b8d0446d00604f1c9378dfa62bffd1bd95bba430 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 23 Sep 2023 00:19:04 -0700 Subject: [PATCH] Fallback gracefully when running on runtimes that only support the Invariant culture --- .../Portable/Completion/PatternMatchHelper.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/Completion/PatternMatchHelper.cs b/src/Features/Core/Portable/Completion/PatternMatchHelper.cs index 6e125ed9bb824..5f639c625e79f 100644 --- a/src/Features/Core/Portable/Completion/PatternMatchHelper.cs +++ b/src/Features/Core/Portable/Completion/PatternMatchHelper.cs @@ -18,11 +18,25 @@ namespace Microsoft.CodeAnalysis.Completion /// internal sealed class PatternMatchHelper(string pattern) : IDisposable { + private static readonly CultureInfo EnUSCultureInfo; + + static PatternMatchHelper() + { + try + { + EnUSCultureInfo = new("en-US"); + } + catch (CultureNotFoundException) + { + // See https://github.com/microsoft/vscode-dotnettools/issues/386 + // This can happen when running on a runtime that is setup for culture invariant mode only. + EnUSCultureInfo = CultureInfo.InvariantCulture; + } + } + private readonly object _gate = new(); private readonly Dictionary<(CultureInfo, bool includeMatchedSpans), PatternMatcher> _patternMatcherMap = new(); - private static readonly CultureInfo EnUSCultureInfo = new("en-US"); - public string Pattern { get; } = pattern; public ImmutableArray GetHighlightedSpans(string text, CultureInfo culture)