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

Culture Information changing #2482

Closed
davidnard opened this issue Dec 12, 2024 · 1 comment
Closed

Culture Information changing #2482

davidnard opened this issue Dec 12, 2024 · 1 comment

Comments

@davidnard
Copy link

davidnard commented Dec 12, 2024

  • Hangfire.Core version: 1.8.15
  • Storage: Hangfire.SqlServer, 1.8.15

We’ve run into an issue in Hangfire versions 1.8.15 and higher, where the CultureInfo settings for worker threads are being modified unexpectedly. Specifically, the PercentDecimalDigits and NumberDecimalDigits properties are altered from their default values (2) to 3, even when the current culture is explicitly set to en-US or another culture where these values are typically 2. This is being seen when a decimal with 4 digits of precision is run through value.ToString("N"). On 1.8.14 and lower, this resulted in 2 digits of precision on the string. Now it appears to be 3.

This behavior is not present in Hangfire version 1.8.14 and below, where the culture settings remain consistent with the application’s global culture configuration.

I can circumvent this by explicitly setting a culture, however I'm wondering if this is a known issue, or if there's a more appropriate way to resolve.


public class SetCultureFilter : IServerFilter
{
    public void OnPerforming(PerformingContext context)
    {
       Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
       Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
    }

    public void OnPerformed(PerformedContext context)
    {
    }
}

@odinserj
Copy link
Member

Thanks for reporting this! There was a change in 1.8.15 that caused Hangfire to use CultureInfo.GetCultureInfo method instead of creating a CultureInfo instances based on its constructor. However, their semantics are different, because GetCultureInfo does not respect user-overridden values set on the OS level:

https://blog.codeinside.eu/2018/05/28/cultureinfo-getculture-vs-new-cultureinfo/

I'm now rolling back the behavior to match the previous one to avoid breaking other installations. The change will be released with 1.8.17.

@odinserj odinserj added this to the Hangfire 1.8.17 milestone Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants