I have the class structure:
public class Task1 : ITask
and
public class Task2 : ITask
and some method:
public static T FromByteArray<T>(byte[] data)
{
if (data == null)
return default(T);
using (var stream = new MemoryStream(data))
using (var reader = new StreamReader(stream, Encoding.UTF8))
return (T)JsonSerializer.Create().Deserialize(reader, typeof(T));
}
where I pass the interface. And get the error: "Could not create an instance of type ITask. Type is an interface or abstract class and cannot be instantiated." I read similar questions, but how can I use the solution with the JsonSerializerSettings in my case? In my case method Deserialize do not have an option for JsonSerializerSettings