You are not showing record
, but I would say that you have something like:
private int id; public int Id { get { return id; } }
there is not much that the serializer can do here to set Id
, so ... it is not. Note: some serializers (for example, t23>) will also refuse to serialize such ones, but JSON serializers tend to be more forgiving, since quite often use only serialization to return data from the web server to the javascript client, including from anonymous types ( which are immutable in C #).
You can try to have a private set
:
private int id; public int Id { get { return id; } private set { id = value; } }
(or alternatively)
public int Id { get; private set; }
If this still does not work - perhaps it should be fully public:
private int id; public int Id { get { return id; } set { id = value; } }
(or alternatively)
public int Id { get; set; }
source share