runtime: System.Globalization.CultureData.GetNFIValues throws System.IndexOutOfRangeException: Index was outside the bounds of the array

In PowerShell repo we get a report with stack trace: https://github.com/PowerShell/PowerShell/issues/12476

Unhandled exception. System.TypeInitializationException: The type initializer for ‘System.Management.Automation.Tracing.PSEtwLog’ threw an exception. —> System.TypeInitializationException: The type initializer for ‘System.Management.Automation.Tracing.PSEtwLogProvider’ threw an exception. —> System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Globalization.CultureData.GetNFIValues(NumberFormatInfo nfi) at System.Globalization.NumberFormatInfo…ctor(CultureData cultureData) at System.Globalization.CultureInfo.get_NumberFormat() at System.Globalization.CultureInfo.GetFormat(Type formatType) at System.Globalization.NumberFormatInfo.get_CurrentInfo() at System.Guid.TryParseExactD(ReadOnlySpan`1 guidString, GuidResult& result) at System.Guid.TryParseGuid(ReadOnlySpan`1 guidString, GuidResult& result) at System.Guid…ctor(String g) at System.Management.Automation.Tracing.PSEtwLogProvider…cctor() — End of inner exception stack trace — at System.Management.Automation.Tracing.PSEtwLog…cctor() — End of inner exception stack trace — at System.Management.Automation.Tracing.PSEtwLog.LogConsoleStartup() at Microsoft.PowerShell.UnmanagedPSEntry.Start(String consoleFilePath, String[] args, Int32 argc) at Microsoft.PowerShell.ManagedPSEntry.Main(String[] args)

I tried to reproduce without success. I don’t know whether the issue in in .Net or OS (Windows Server 2016). Cuture 1053 sv-SE Swedish (Sweden).

I guess the Guid ctor is called in follow code:

        internal static readonly Guid ProviderGuid = new Guid("F90714A8-5509-434A-BF6D-B1624C8A19A2");

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 28 (16 by maintainers)

Most upvoted comments

Thanks to you both. It seems, that the standard digits were removed, Don’t know why and if it was with purpose. But I don’t have a clue, why this is throwing the error.

Only for testing, I have build an app with the sample code from here:

NumberFormatInfo.CurrentInfo

It is throwing the exception build against dotnet core 3.1, but it isn’t doing it with the full framework. It is above my horizont, to say it is caused by one or the other. It was only a last try to enclose this behaviour.

Usually, the globalization data on Windows are stored in the file C:\Windows\system32\locale.nls. The UI is just to customize this data for the current user.

I’ll try to send this issue to the Windows team to know if they know about it.

CC @ShawnSteele

Thanks again, at the end the result was the same, but my way was a bit longer.

if I exclude every result with 11, then it looks more clear now:

sv-SE … 10 zh-CHS … 0 zh-CHT … 0

@Sascha-69 is it possible on the machine which repro the issue to run the following code and send back the results?

        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
        public static extern int GetLocaleInfoEx(string lpLocaleName, int LCType, char [] lpLCData, int cchData);

        // ....

            const int LOCALE_SNATIVEDIGITS = 0x00000013;   // native digits for 0-9
            char[] chars = new char[100];
            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                int result = GetLocaleInfoEx(ci.Name, LOCALE_SNATIVEDIGITS, chars, chars.Length);
                Console.WriteLine($"{ci.Name} .. {result}");
            }

@iSazonov properly you are right. we had some issues before which we have fixed awhile ago and .Net Core 3.1 should have such fixes. For this one, I don’t think this is actionable from .NET side. Please try to get a repro and then report the issue to the Windows team through Windows 10 Feedback Hub. I am closing this issue here, feel free to respond back if you think we can help in anything and we’ll be happy to do so.