Humanizer
Humanizer copied to clipboard
The type initializer for 'Humanizer.Configuration.Configurator' threw an exception.
I am using the Humanizer.core in .NET Core 6 RC1 in Blazor WASM App.
This is what is throwing error in .razor page. @searchResult.AlerSentTime?.Humanize(culture:CultureInfo.InvariantCulture);
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: The type initializer for 'Humanizer.Configuration.Configurator' threw an exception.
System.TypeInitializationException: The type initializer for 'Humanizer.Configuration.Configurator' 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.
at System.Globalization.CultureInfo..ctor(String name, Boolean useUserOverride)
at System.Globalization.CultureInfo..ctor(String name)
at Humanizer.Localisation.Formatters.DefaultFormatter..ctor(String localeCode) in /_/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs:line 19
at Humanizer.Configuration.FormatterRegistry..ctor() in /_/src/Humanizer/Configuration/FormatterRegistry.cs:line 9
at Humanizer.Configuration.Configurator..cctor() in /_/src/Humanizer/Configuration/Configurator.cs:line 28
--- End of inner exception stack trace ---
at Humanizer.DateHumanizeExtensions.Humanize(DateTime input, Nullable`1 utcDate, Nullable`1 dateToCompareAgainst, CultureInfo culture) in /_/src/Humanizer/DateHumanizeExtensions.cs:line 26
at Humanizer.DateHumanizeExtensions.Humanize(Nullable`1 input, Nullable`1 utcDate, Nullable`1 dateToCompareAgainst, CultureInfo culture) in /_/src/Humanizer/DateHumanizeExtensions.cs:line 41
at GetInLineV6New.Client.Pages.Org.OperateOrgLocationTerminal.<>c__DisplayClass31_0.<BuildRenderTree>b__16(RenderTreeBuilder __builder3) in c:\Users\admin\source\repos\XXXXXV6New\XXXXV6New\Client\Pages\Org\OperateOrgLocationTerminal.razor:line 92
at Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize`1[[XXXXXV6New.Shared.Models.DTO_Token, GetInLineV6New.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].BuildRenderTree(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
Are you setting the global invariant mode anywhere as per https://aka.ms/GlobalizationInvariantMode?
Yes I am in setting in project file as shown in the document.
Sent from Yahoo Mail for iPhone
On Saturday, September 25, 2021, 8:59 AM, Claire Novotny @.***> wrote:
Are you setting the global invariant mode anywhere as per https://aka.ms/GlobalizationInvariantMode?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.
Hi, receive same error on console application net6.0
Hi,
I got the above error after migrating my NET 5 application to NET 6. I was not explicitly setting the Globalization configuration setting in the runtimeconfig.json
or Project file. Upon further reading I discovered this might have something to do with the following breaking change, Culture creation and case mapping in globalization-invariant mode. I don't happen to experience this issue when developing locally, however, once I deploy using the Alpine docker image. The documentation does explicitly mention
Globalization-invariant mode is enabled by default on some Docker containers, for example, Alpine containers.
In my code, I create a custom type that implements ICollectionFormatter. I was adding this to the Configurator CollectionFormatters, as such.
Humanizer.Configuration.Configurator.CollectionFormatters.Register("en", new CustomFormatter("and"));
The fix was to disable InvariantGlobalization in the Project file, by setting InvariantGlobalization to false. Additionally, in my Dockerfile, shortly after I pull the Alpine image, I needed to install the ICU packages.
ARG AspNetVersion
FROM mcr.microsoft.com/dotnet/aspnet:${AspNetVersion} AS base
WORKDIR /app
...
RUN apk add --no-cache icu-libs
I found this article by Andrew Lock to be help!
I hope this helps!
I having the same issue. .NET 6 application using GlobalizationInvariantMode.
Is there any way to make this library work in such applications? In my case, it's not in my hands to disable GlobalizationInvariantMode. Thanks!
Hi, receive same error on console application net6.0
Now work
Same problem here, and I don't want to disable InvariantGlobalization
.
Can anyone merge the PR that fixes this??
The same issue happened today .NET 8 Docker (Alpine). Is there a fix guys?
@sangeethnandakumar there is a PR. https://github.com/Humanizr/Humanizer/pull/1213
but, before i merge it, i need some tests to confirm it fixes the actual issue