'JsonSerializationException 'Unable to find a constructor' on Xamarin.Android with .NET Standard Library
I have used Xamarin Native UI for Android application and Created different class library for API call and data Deserialize api data using Newtonsoft.Json.
That class library Target Framework is .NET Standar 2.0.
As I have added that reference to the console application so its working fine but same reference i have add in Android project its throw error.
**Error Details**
Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute.
As per error message i have used attribute JsonConstructor for default constructor of class.
Example:
public class TestClass
{
[JsonConstructor]
public TestClass()
{
}
}
Solution 1:[1]
Try using PreserveAttribute at the top of your class
[PreserveAttribute(AllMembers = true)]
public class TestClass
{
public TestClass() {}
}
add one more class PreserveAttribute in class library
public sealed class PreserveAttribute : System.Attribute
{
public bool AllMembers;
public bool Conditional;
}
Edit Linking- Sdk & user assemblies
Skip linking assemblies- Newtonsoft.Json;
add Newtonsoft.Json in your Skip linking assemblies option
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
