Hello,
I’m facing an issue with the GetVersionsAsync function. As soon as I call it, I get the following exception:
FormatException: String was not recognized as a valid DateTime.
System.DateTimeParse.ParseExact (System.ReadOnlySpan`1[T] s, System.ReadOnlySpan`1[T] format, System.Globalization.DateTimeFormatInfo dtfi, System.Globalization.DateTimeStyles style)
System.DateTime.ParseExact (System.String s, System.String format, System.IFormatProvider provider, System.Globalization.DateTimeStyles style)
Newtonsoft.Json.Converters.IsoDateTimeConverter.ReadJson (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue, Newtonsoft.Json.JsonSerializer serializer)
It seems like the date format being deserialized in the following function is not in the correct format, but Unity is the one sending me the start and end date, and I don’t know what to do to fix the problem:
public static T TryDeserializeResponse<T>(HttpClientResponse response)
{
var settings = new JsonSerializerSettings
{
MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore,
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
// Custom date format handling
DateFormatHandling = DateFormatHandling.IsoDateFormat,
DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind
};
try
{
var deserializedJson = GetDeserializedJson(response.Data);
return JsonConvert.DeserializeObject<T>(deserializedJson, settings);
}
catch (Exception e)
{
// Include data in the exception for analysis
string debugMessage = $"Error deserializing response. Data: {response.Data}";
throw new ResponseDeserializationException(response, e, debugMessage);
}
}
Has anyone experienced this kind of issue or has any idea how to fix this?
Thank you!