Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Runtime.Serialization.InvalidDataContractException: No set method for property

Tags:

c#

wcf

As the error shows I don't have a setter for my property, but I don't want a setter, it should be readonly.

like image 680
BreakHead Avatar asked Mar 02 '10 12:03

BreakHead


2 Answers

Edited: Make the setter internal.

This will still be settable within the assembly, but it is a nice trick that works well when used on data objects located within an assembly that is consumed by others, as those consuming assemblies will not be able to set the property, but the various serializers can.

like image 134
slugster Avatar answered Sep 23 '22 17:09

slugster


Remember that WCF needs to create an instance of the object from its serialized representation (often XML) and if the property has no setter it cannot assign a value. Objects are not transferred between the client and the server but only serialized representations, so the object needs to be reconstructed at each end.

like image 38
Darin Dimitrov Avatar answered Sep 21 '22 17:09

Darin Dimitrov