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

Windows Server 2016 - The type initializer for 'TimeZoneNames.TZNames' threw an exception. #65

Open
akirby opened this issue Apr 1, 2021 · 7 comments
Assignees
Labels

Comments

@akirby
Copy link

akirby commented Apr 1, 2021

I have the following implementation in .NET Framework 4.7.1

var tzNames = TZNames.GetAbbreviationsForTimeZone(tz.Id, CultureInfo.CurrentCulture.Name);

which throws the following error with stack trace:
The type initializer for 'TimeZoneNames.TZNames' threw an exception.
at TimeZoneNames.TZNames.GetLanguageKey(String languageCode, Boolean forDisplayNames)
at TimeZoneNames.TZNames.GetAbbreviationsForTimeZone(String timeZoneId, String languageCode)

I have run windows update to ensure that I am current, but not sure if i need to install some other dependency on the server.

Running Get-Culture on the box returns

LCID             Name             DisplayName
----             ----             -----------
1033             en-US            English (United States)

I have also run txutil to update the Timezone registry, but not sure if this is the correct step.

Please let me know if there is something else I can check on my server, as this code works on my dev machine.

@akirby
Copy link
Author

akirby commented Apr 1, 2021

tz.Id verified through logging is "Eastern Standard Time".

The tz object is from TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

@mattjohnsonpint
Copy link
Owner

Nothing else should need to be installed. Could you please do some debugging on the application itself to see if "en-US" is being passed for the language code?

I hit something similar a long time ago with #32, but that has been resolved.

Could you please provide the specific exception name and message? I only see the stack trace. Thanks.

(Also, you should probably be using the CurrentUICulture instead of CurrentCulture, though I doubt that is the cause of the exception.)

@robin-salih-fluke
Copy link

I had a similar issue, this test demonstrates it:

image

The call to TimeZoneInfo.FindSystemTimeZoneById adds another entry to the list of windows time zones, which then causes ToDictionary to throw an exception as it is the duplicate key (case differs).

@akirby
Copy link
Author

akirby commented Jul 27, 2021

@robin-salih-fluke that is interesting.

@Wangota
Copy link

Wangota commented Mar 3, 2022

@mattjohnsonpint

Any chance this is fixed?
I am experiencing the same exact issue: See stacktrace below.
lean forDisplayNames)
at TimeZoneNames.TZNames.GetTimeZonesForCountry(String countryCode, String languageCode, DateTimeOffset threshold)
at BusinessLogic.Utils.TimeZones.TimeZonesByCountry(String countryCode, String language)
at Events.Controllers.EventController.CountryTimeZones(String countryID)

Exception Message: The type initializer for 'TimeZoneNames.TZNames' threw an exception."

@Wangota
Copy link

Wangota commented Mar 3, 2022

@akirby @robin-salih-fluke
Have you resolved this issue?

@mattjohnsonpint mattjohnsonpint self-assigned this Mar 4, 2022
@mattjohnsonpint
Copy link
Owner

I'll take another look. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants