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

Error on TimeZoneInfo.FromSerializedString #91312

Closed
skyoxZ opened this issue Aug 30, 2023 · 2 comments
Closed

Error on TimeZoneInfo.FromSerializedString #91312

skyoxZ opened this issue Aug 30, 2023 · 2 comments

Comments

@skyoxZ
Copy link
Contributor

skyoxZ commented Aug 30, 2023

Description

TimeZoneInfo.FromSerializedString throws on some time zones.

Reproduction Steps

foreach (TimeZoneInfo t in TimeZoneInfo.GetSystemTimeZones())
{
    string s = t.ToSerializedString();
    try
    {
        TimeZoneInfo.FromSerializedString(s);
    }
    catch (Exception ex)
    {
        Console.WriteLine(s);
        Console.WriteLine(ex);
        return;
    }
}

Expected behavior

Empty output.

Actual behavior

Pacific/Niue;-660;(UTC-11:00) Niue Time;Niue Time;GMT-11:00;[01:01:0001;12:31:0001;0;[1;00:00:00;1;1;];[1;23:59:59.999;12;31;];-19;][01:01:0002;12:31:1951;0;[1;00:00:00;1;1;];[1;23:59:59.999;12;31;];-19;][01:01:1952;10:16:1952;0;[1;00:00:00;1;1;];[1;00:19:39.999;10;16;];-19;][10:16:1952;12:31:1952;0;[1;00:19:40;10;16;];[1;23:59:59.999;12;31;];-20;][01:01:1953;12:31:1963;0;[1;00:00:00;1;1;];[1;23:59:59.999;12;31;];-20;][01:01:1964;07:01:1964;0;[1;00:00:00;1;1;];[1;00:19:59.999;7;1;];-20;];
System.Runtime.Serialization.SerializationException: An error occurred while deserializing the object.  The serialized data is corrupt.
 ---> System.InvalidTimeZoneException: The elements of the AdjustmentRule array must be in chronological order and must not overlap.
   at System.TimeZoneInfo.ValidateTimeZoneInfo(String id, TimeSpan baseUtcOffset, AdjustmentRule[] adjustmentRules, Boolean& adjustmentRulesSupportDst)
   at System.TimeZoneInfo..ctor(String id, TimeSpan baseUtcOffset, String displayName, String standardDisplayName, String daylightDisplayName, AdjustmentRule[] adjustmentRules, Boolean disableDaylightSavingTime, Boolean hasIanaId)
   at System.TimeZoneInfo.StringSerializer.GetDeserializedTimeZoneInfo(String source)
   --- End of inner exception stack trace ---
   at System.TimeZoneInfo.StringSerializer.GetDeserializedTimeZoneInfo(String source)
   at Program.<Main>$(String[] args)

Regression?

No response

Known Workarounds

No response

Configuration

Ubuntu 22 & MacOS Ventura
.NET 6 & .NET 7

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 30, 2023
@ghost
Copy link

ghost commented Aug 30, 2023

Tagging subscribers to this area: @dotnet/area-system-datetime
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

TimeZoneInfo.FromSerializedString throws on some timezone.

Reproduction Steps

foreach (TimeZoneInfo t in TimeZoneInfo.GetSystemTimeZones())
{
    string s = t.ToSerializedString();
    try
    {
        TimeZoneInfo.FromSerializedString(s);
    }
    catch (Exception ex)
    {
        Console.WriteLine(s);
        Console.WriteLine(ex);
        return;
    }
}

Expected behavior

Empty output.

Actual behavior

Pacific/Niue;-660;(UTC-11:00) Niue Time;Niue Time;GMT-11:00;[01:01:0001;12:31:0001;0;[1;00:00:00;1;1;];[1;23:59:59.999;12;31;];-19;][01:01:0002;12:31:1951;0;[1;00:00:00;1;1;];[1;23:59:59.999;12;31;];-19;][01:01:1952;10:16:1952;0;[1;00:00:00;1;1;];[1;00:19:39.999;10;16;];-19;][10:16:1952;12:31:1952;0;[1;00:19:40;10;16;];[1;23:59:59.999;12;31;];-20;][01:01:1953;12:31:1963;0;[1;00:00:00;1;1;];[1;23:59:59.999;12;31;];-20;][01:01:1964;07:01:1964;0;[1;00:00:00;1;1;];[1;00:19:59.999;7;1;];-20;];
System.Runtime.Serialization.SerializationException: An error occurred while deserializing the object.  The serialized data is corrupt.
 ---> System.InvalidTimeZoneException: The elements of the AdjustmentRule array must be in chronological order and must not overlap.
   at System.TimeZoneInfo.ValidateTimeZoneInfo(String id, TimeSpan baseUtcOffset, AdjustmentRule[] adjustmentRules, Boolean& adjustmentRulesSupportDst)
   at System.TimeZoneInfo..ctor(String id, TimeSpan baseUtcOffset, String displayName, String standardDisplayName, String daylightDisplayName, AdjustmentRule[] adjustmentRules, Boolean disableDaylightSavingTime, Boolean hasIanaId)
   at System.TimeZoneInfo.StringSerializer.GetDeserializedTimeZoneInfo(String source)
   --- End of inner exception stack trace ---
   at System.TimeZoneInfo.StringSerializer.GetDeserializedTimeZoneInfo(String source)
   at Program.<Main>$(String[] args)

Regression?

No response

Known Workarounds

No response

Configuration

Ubuntu 22
.NET 6 & .NET 7

Other information

No response

Author: skyoxZ
Assignees: -
Labels:

area-System.DateTime

Milestone: -

@skyoxZ
Copy link
Contributor Author

skyoxZ commented Aug 30, 2023

Oh it has been reported. Duplicate #19794

@skyoxZ skyoxZ closed this as completed Aug 30, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Aug 30, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant