I am binding DataGrid.ItemsSource
property to the List
object. I am getting datas through Silverlight-enabled WCF
The problem is the WCF DataContract
is an inter-operable mechanism that can be used across languages and platforms.
If you take a look to serialized data generated by the DataContractSerializer
(or its code in System.Runtime.Serialization.dll
, specifically InternalWriteObjectXyz()
methods) you'll see that it merely serializes values into a simple XML message. Nothing related to .NET Framework will be there so all kind of attributes, both custom and compiler generated, will be stripped out and won't even received by the client.
It works creating a copy of your data and sending them from server to client, clients will then create a new class with the same signature. Note: a NEW CLASS with the same signature, NOT JUST A NEW OBJECT of the original class.
Of course there are some workaround for this. You may write your own serializer (see this post on SO for an example) or your own ISerializationSurrogate
.
If you can deploy/share your assemblies to your clients you have a nice workaround: just deploy them and DataContractSerializer
will build the right object on your clients (exactly the same one you had on the server, with all its attributes). Just remember that: