I have function which serialize objects. It is working fine in every case except when I run with specific object. This is object of class which contains Tasks. But I don't see why would this be problem.
In debug mode code is just stuck without any error, or any exception. Just stop and waiting for ever. Also to mention that this serialization is called in running Task, but also I am not sure why would this be problem.
I have also set attribute [NonSerialized] to all Task properties but still nothing.
[NonSerialized]
private Task<bool> isConnected;
public Task<bool> IsConnected
{
get { return isConnected; }
set { isConnected = value; }
}
This is my function:
public static string ToJson(this object obj)
{
try
{
var res = JsonConvert.SerializeObject(obj, Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
return res;
}
catch
{
return $"Object {obj.ToString()} is not serializable.";
}
}
This is object I try to serialize:
