Quantcast
Channel: Json.NET
Viewing all articles
Browse latest Browse all 1767

Closed Issue: TimeZoneNotFoundException in WriteDateTimeString (System.IO.TextWriter, DateTime, DateFormatHandling, Char) [23775]

$
0
0
DLL : Json45r11\Bin\Net40\Newtonsoft.Json.dll
Framework : Mono 4.0.30319.1

Invoked code (from ildasm) :

result = JsonConvert.SerializeObject(this.Data);

Exception :

System.TimeZoneNotFoundException: Exception of type 'System.TimeZoneNotFoundException' was thrown.
at System.TimeZoneInfo.get_Local () [0x00048] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.8\mcs\class\System.Core\System\TimeZoneInfo.cs:100
at Newtonsoft.Json.Utilities.DateTimeUtils.GetUtcOffset (DateTime d) [0x00000] in :0
at Newtonsoft.Json.JsonConvert.WriteDateTimeString (System.IO.TextWriter writer, DateTime value, DateFormatHandling format, Char quoteChar) [0x00000] in :0
...
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in :0

Your code:

internal static void WriteDateTimeString(TextWriter writer, DateTime value, DateFormatHandling format, char quoteChar)
{
JsonConvert.WriteDateTimeString(writer, value, value.GetUtcOffset(), value.Kind, format, quoteChar);
}

Workaround :

Replace all usages of `.GetUtcOffset()` in all source codes. For each error, replace the expected TimeSpan by `TimeSpan.Zero`. This fix will drop support of timezones but my project uses only UTC-based dates.

The error occurs when serializing DateTime values of any kind (Local,Unknown,Utc).
Comments: Report this issue to the Mono project.

Viewing all articles
Browse latest Browse all 1767

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>