No parameterless constructor defined for type of 'System.String' during JSON deserialization
Parameterless constructors need for any kind of deserialization. Imagine that you are implementing a deserializer. You need to:
- Get a type of object from the input stream (in this case it's string)
- Instantiate the object. You have no way to do that if there is no default constructor.
- Read the properties/value from stream
- Assign the values from the stream to the object created on step 2.
I had the same issue and this was what fixed the issue.
Cheers!
//Deserializing Json object from string
DataContractJsonSerializer jsonObjectPersonInfo =
new DataContractJsonSerializer(typeof(PersonModel));
MemoryStream stream =
new MemoryStream(Encoding.UTF8.GetBytes(userInfo));
PersonModel personInfoModel =
(PersonModel)jsonObjectPersonInfo.ReadObject(stream);