runtime: .NET 6 TimeZoneInfo.FindSystemTimeZoneById does not support IANA timezone ids on Windows Server 2016 & 2019
Description
As announced here: https://devblogs.microsoft.com/dotnet/date-time-and-time-zone-enhancements-in-net-6/ starting with .NET 6 TimeZoneInfo.FindSystemTimeZoneById should now support IANA timezone ids. That works just fine on Windows 10/10 & Windows Server 2022. It does not work on Windows Server 2016 & 2019 thought. Those are versions user by Azure App Services today. So, this functionality simple does not work on Azure.
Reproduction Steps
System.Console.WriteLine(“{0}”, System.TimeZoneInfo.FindSystemTimeZoneById(“Europe/Copenhagen”).Id);
Expected behavior
IANA timezone is resolved no matter what OS the code is run on.
Actual behavior
It is not resolved.
Regression?
Technically, it’s not a regression. But, TimeZoneConverter library which was recommended to use before seems to be struggling to find a new maintainer: https://github.com/mattjohnsonpint/TimeZoneConverter/issues/105 which means it may not have regular updates in the future.
Known Workarounds
Add this to a project file helps:
<ItemGroup>
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9" />
<RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2" />
</ItemGroup>
This, however, has to be done to every single project which is tedious, time-consuming and error-prone. Moreover, if we have a test DLL which uses TimeZoneInfo.FindSystemTimeZoneById, this workaround does not work (it only applies to EXEs).
Configuration
No response
Other information
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 18 (10 by maintainers)
I just hit this problem, too. I read the blog post announcing the new features in .NET 6, then happily removed references to TimeZoneConverter from my project because .NET supports it natively now! But when I pushed my changes, my units tests failed on GitHub Actions because IANA names do not work on Windows Server 2019. How do we apply the necessary “app-local ICU” configuration for unit tests?
The proposed solution does also work for unit tests. You just have to add the same properties/package to the test projects too.
Reopen to try find a solution for the unit tests.