mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-22 19:10:41 -10:00
Json.NET serializes the collection by enumerating it, without taking into account any of its fields like the binary serializer does, and deserializes it by adding the items back to the collection, without initializing the fields. However, it does still call the `OnSerializing`/`OnSerialized`/`OnDeserializing`/`OnDeserialized` methods. When it calls `OnDeserialized`, a NullRef exception is thrown when we try to access the `_monitor` field because the field has not been initialized, unlike with binary deserialization, where the field would have been initialized from the serialized binary data. A workaround is to simply check `if (_monitor != null)` before accessing it in `OnDeserialized`. Commit migrated from https://github.com/dotnet/corefx/commit/a3b8dc33644933c74aa1e58fb07f69df18301e09