runtime: IndexOutOfRangeException in NumberFormatInfo
From @bmpcon on Friday, 17 August 2018 08:49:05
Hello,
when deploying a vanilla ASP.NET Core (2.1.1) WebApi application to our enterprise server (Windows 2016) we get the following exception when doing a request from localhost:
Application started. Press Ctrl+C to shut down.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLG41UURV0D2", Request id "0HLG41UURV0D2:00000001": An unhandled exception was thrown by the application.
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.NumberFormatInfo.get_CurrentInfo()
at System.Int32.TryParse(String s, Int32& result)
at Microsoft.AspNetCore.HttpOverrides.Internal.IPEndPointParser.TryParse(String addressWithPort, IPEndPoint& endpoint)
at Microsoft.AspNetCore.HttpOverrides.ForwardedHeadersMiddleware.ApplyForwarders(HttpContext context)
at Microsoft.AspNetCore.HttpOverrides.ForwardedHeadersMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Hosting.Internal.HostingApplication.ProcessRequestAsync(Context context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
As a workaround we were able to solve the problem with changing the thread culture to en-us:
private static void SetCultureToUs()
{
var cultureInfo = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
}
Copied from original issue: aspnet/BasicMiddleware#356
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (20 by maintainers)
It would be a good idea if you can collect the registry contents on the failing machine of the following registry paths:
Maybe this can give any clue.
Do you have any custom culture data installed for the sv-SE culture?
From a cursory inspection of the method, it would seem this could only come from: https://github.com/dotnet/coreclr/blob/e0d680101a93797c9e1a049bf582a874e2cb4113/src/System.Private.CoreLib/shared/System/Globalization/CultureData.cs#L2364 which assumes we’ll get back exactly ten characters from the call to Windows (one for each digit 0 to 9).
Could you try running this and sharing the output:
?