ClickHouseClient icon indicating copy to clipboard operation
ClickHouseClient copied to clipboard

[.net 6] System.TimeZoneNotFoundException: The time zone ID 'Asia/Almaty' was not found on the local computer.

Open Yerkon opened this issue 3 years ago • 7 comments

Hello, After upgrading project from .net 5 to .net 6, error occurs on Windows Server 2019.

`

System.TimeZoneNotFoundException: The time zone ID 'Asia/Almaty' was not found on the local computer. at System.TimeZoneInfo.FindSystemTimeZoneById(String id) at Octonica.ClickHouseClient.Utils.TimeZoneHelper.GetTimeZoneInfo(String timeZone) at Octonica.ClickHouseClient.Types.DateTimeTypeInfo.GetTimeZone() at Octonica.ClickHouseClient.Types.DateTimeTypeInfo.CreateColumnWriter[T](String columnName, IReadOnlyList1 rows, ClickHouseColumnSettings columnSettings) at Octonica.ClickHouseClient.ClickHouseParameter.ParameterColumnWriterBuilder.Dispatch[T]() at Octonica.ClickHouseClient.Utils.TypeDispatcher.Dispatcher1.Dispatch[T](ITypeDispatcher1 dispatcher) at Octonica.ClickHouseClient.Utils.TypeDispatcher.Dispatch[TOut](Type type, ITypeDispatcher1 dispatcher) at Octonica.ClickHouseClient.ClickHouseParameter.CreateParameterColumnWriter(IClickHouseTypeInfoProvider typeInfoProvider) at Octonica.ClickHouseClient.ClickHouseCommand.<>c__DisplayClass88_0.<CreateParameterTableWriter>b__0(ClickHouseParameter p) at System.Linq.Enumerable.SelectIListIterator2.ToList() at Octonica.ClickHouseClient.ClickHouseTableWriter..ctor(String tableName, Int32 rowCount, IEnumerable1 columns) at Octonica.ClickHouseClient.ClickHouseCommand.CreateParameterTableWriter(IClickHouseTypeInfoProvider typeInfoProvider, String tableName) at Octonica.ClickHouseClient.ClickHouseCommand.SendQuery(Session session, CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at Octonica.ClickHouseClient.ClickHouseCommand.SendQuery(Session session, CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) at Octonica.ClickHouseClient.ClickHouseCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean ignoreProfileEvents, Boolean async, CancellationToken cancellationToken) at Octonica.ClickHouseClient.ClickHouseCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean ignoreProfileEvents, Boolean async, CancellationToken cancellationToken) at Octonica.ClickHouseClient.ClickHouseCommand.ExecuteReaderAsync() at Marketing.Utils.Database.Clickhouse.ClickhouseHelper.<>c__DisplayClass26_0.<<ExecuteReader>b__0>d.MoveNext() in --- End of stack trace from previous location ---

`

"Octonica.ClickHouseClient" Version="2.2.9" For "Octonica.ClickHouseClient" Version="2.2.8" the same

Yerkon avatar Oct 20 '22 06:10 Yerkon

But when running locally (Windows 10), it works

Yerkon avatar Oct 20 '22 08:10 Yerkon

I fixed it by forcing local ICU through nuget App-local ICU. Probably, there is no ICU installed on Windows server 2019

Yerkon avatar Oct 20 '22 09:10 Yerkon

I have the same problem on Windows 10 with " System.TimeZoneNotFoundException: The time zone ID 'Europe/Berlin' was not found on the local computer.". @Yerkon How did you solve the problem? I added the following lines in my .csproj file, but I still get the error.

<ItemGroup>
    <RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="72.1.0.3" />
    <PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="72.1.0.3" />
</ItemGroup>

MrDoe avatar Feb 05 '24 14:02 MrDoe

@MrDoe, only include in Windows platform:

<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
   <PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9"/>
   <RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2"/>
</ItemGroup>

Also, in program you can check if IcuMode enabled with method:

 private static bool IcuMode()
 {
     SortVersion sortVersion = CultureInfo.InvariantCulture.CompareInfo.Version;
     byte[] bytes = sortVersion.SortId.ToByteArray();
     int version = (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | bytes[0];

     return version != 0 && version == sortVersion.FullVersion;
 }

Yerkon avatar Feb 06 '24 04:02 Yerkon

@Yerkon Thanks for your answer! I tried this, the IcuMode works, but I still get the error. Maybe it is an issue with .NET 8 running on Windows 10.

I debugged the library and changed

[MethodImpl(MethodImplOptions.AggressiveInlining)]
 static partial void GetTimeZoneInfoImpl(string timeZone, ref TimeZoneInfo? timeZoneInfo)
 {
     timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone);
 }

to

[MethodImpl(MethodImplOptions.AggressiveInlining)]  
 static partial void GetTimeZoneInfoImpl(string timeZone, ref TimeZoneInfo? timeZoneInfo)  
 {  
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))  
     {  
         timeZone = TZConvert.IanaToWindows(timeZone);  
     }  
     timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone);  
 }

in TimeZoneHelper.Net6.0.cs.

Now it works, but I get another error: ""TODO: add support for custom serialization." But I guess this is another issue. Do you know by chance what "custom serialization" means?

The error is occuring when I try to select a DateTime64 column. As a workaround, I'm currently using toString(myDateTime64Column) in my queries.

MrDoe avatar Feb 07 '24 08:02 MrDoe

@MrDoe, maybe @victor-sushko will help?

Yerkon avatar Feb 09 '24 03:02 Yerkon

Now it works, but I get another error: ""TODO: add support for custom serialization." But I guess this is another issue. Do you know by chance what "custom serialization" means?

The error is occuring when I try to select a DateTime64 column. As a workaround, I'm currently using toString(myDateTime64Column) in my queries.

In recent versions ClickHouse "breaks" wire protocol. You can disable sparse columns feature or wait for release with sparse column see #85 (couple of days)

SergeyMirvoda avatar Mar 07 '24 10:03 SergeyMirvoda