JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.73k stars 3.25k forks source link

Library ignores NonSerialized attribute in release version UWP #2821

Open diegotonetti99 opened 1 year ago

diegotonetti99 commented 1 year ago

As stated in the title, the library is serializing all attributes of a c# class if standard NonSerialized attribute is used. Every nuget package is up to date to the last version. The library works fine in debug mode, only serializing the desired attributes.

Steps to reproduce

[Serialized]
public class ImageContent {
     public Rect Rectangle;
     public string ImageFile;
     [NonSerialized] public Image image;
}

this fails because Image object can't be serialized, but also with other objects that can be serialized the NonSerialized attribute is ignored in release mode.

Workaround

Substitute the Serialized and NonSerialized attributes with

[JsonObject]
public class ImageContent {
     public Rect Rectangle;
     public string ImageFile;
     [JsonIgnore] public Image image;
}