Newtonsoft.Json
Newtonsoft.Json copied to clipboard
.net project output {} when serializing the model in publish mode (v9-v13.0.3)
User userInfo = new User { id="11011", name="zhangsan", age=12,sex= false,address= "sicuan" }; Console.WriteLine(userInfo.id); string json=JsonConvert.SerializeObject(userInfo); Console.WriteLine(json);
Since i don't know what settings you used for the publish mode, i would like to ask you to narrow down the problem space.
First, in case you use AOT compiling, disable it and see whether the json serialization will start behaving. If not, also disable code trimming for publishing and see whether this will help.
If that doesn't seem to make the code behave either, you'll need to tell us more details about your problem: What is the build/platform target you are publishing for? What are the publish settings you are using? What build environment/tools are you using?
The problem found is the use of 'Obfuscar' plugin caused by the bug
I just had a similar problem, I was using JObject.ToString() and was also getting "{}" as the output. Disabling "Trim unused code" in publish options fixed the problem. Publish options were Release | Any CPU, net7.0, Self-Contained, linux-x64, produce single file