C
C#13mo ago
arch_il

✅ Get this error while trying to Deserialize object

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Text.Json.dll: 'Each parameter in the deserialization constructor on type 'AnimationTesting.Models.Room' must bind to an object property or field on deserialization. Each parameter name must match with a property or field on the object. The match can be case-insensitive.'
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Text.Json.dll: 'Each parameter in the deserialization constructor on type 'AnimationTesting.Models.Room' must bind to an object property or field on deserialization. Each parameter name must match with a property or field on the object. The match can be case-insensitive.'
This is an error I get. I am not even sure what part of code to send, which would cause an issue.
6 Replies
jcotton42
jcotton4213mo ago
can you show the $code for AnimationTesting.Models.Room? in particular it sounds like STJ is trying to use constructor deserialization
MODiX
MODiX13mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
arch_il
arch_il13mo ago
There are objects of other classes inside Room class. Should all of them jave [JsonConstructor]?
jcotton42
jcotton4213mo ago
you only need JsonConstructor if there are multiple parameterized constructors on the class
For a class, if the only constructor is a parameterized one, that constructor will be used. For a struct, or a class with multiple constructors, specify the one to use by applying the [JsonConstructor] attribute. When the attribute is not used, a public parameterless constructor is always used if present.
arch_il
arch_il13mo ago
thanks for help. My classes are too complicated to solve this problem that simply. I will create json models for each.
Want results from more Discord servers?
Add your server
More Posts