Hi,
As the error shows I dnt have setter for my property, but I dnt want setter its just a readonly..any Ideas??
Will really appreciate it
Thanks
Hi,
As the error shows I dnt have setter for my property, but I dnt want setter its just a readonly..any Ideas??
Will really appreciate it
Thanks
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.
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.
Your question's a bit vague, but I guess this is the answer you're looking for:
Default Serialization will only work for read-write properties, because you can't rehydrate an object without setting property values. If you want it to work with the property being readonly, you need to implement the serialization interface yourself, rather than just adding attributes.
Assuming you're using DataContract serialization, I think the best option is to implement ISerializable and implement the methods yourself.
I choosed a different way: set{Throw new Exception("You can't set value for this property.")} Thanksss for your Inputs Dan and Slugster