0

I'm trying to (de)serialize a complex class that, among other things contains a member that has a type class that implements IEnumerable.

public class ClassToSerialize { public IEnumerableClass Foo; }
public class IEnumerableClass: IEnumerable<Bar> { ... }

The serialization works just fine. When deserializing I get a "Newtonsoft.Json.JsonSerializationException: 'Cannot create and populate list type" exception. The normal solution would be to decorate IEnumerableClass with [JsonObject] (as per this answer). The problem is I do not have access to the class code so I need a solution from within the (de)serializer itself. I have tried creating a custom contract resolver but so far have not had any success.

rotSin
  • 231
  • 1
  • 3
  • 13
  • Does this answer your question? [Json.net serialization of custom collection implementing IEnumerable](https://stackoverflow.com/questions/7567097/json-net-serialization-of-custom-collection-implementing-ienumerablet) – Lennart Stoop Dec 16 '21 at 12:04
  • *I have tried creating a custom contract resolver but so far have not had any success.* -- I have closed your question as a dup of one that shows how to use a custom contract resolver as required. If for some reason it doesn't work for you, please [edit] your question to share a [mcve]. – dbc Dec 16 '21 at 17:26

0 Answers0