Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

Readonly collection support in DataContractSerializer?

 
 
Thread Tools Display Modes
Old 11-08-2006   #1 (permalink)
MrAnon
Guest


 

Readonly collection support in DataContractSerializer?

Just getting to grips with the new (to me) DataContractSerializer
through WCF and my class is failing to serialize because a [DataMember]
doesn't have a setter. But there's a good reason for this - the
property is a readonly collection, you know...

private List<SomeType> _things = new List<SomeType>();

[DataMember]
public List<SomeType> Things
{
get { return _things; }
}

The old XmlSerializer used to understand this and play nicely but the
DataContract serializer doesn't seem to want to.

Any ideas? Am I missing an attribute somewhere?

Old 11-08-2006   #2 (permalink)
Arkady Frenkel
Guest


 

Re: Readonly collection support in DataContractSerializer?

You do can continue to use XmlSerializer if it's good for you
http://msdn.microsoft.com/msdnmag/is...efault.aspx#S4
Arkady

"MrAnon" <josh.twist@gmail.com> wrote in message
news:1162992886.697261.198840@i42g2000cwa.googlegroups.com...
> Just getting to grips with the new (to me) DataContractSerializer
> through WCF and my class is failing to serialize because a [DataMember]
> doesn't have a setter. But there's a good reason for this - the
> property is a readonly collection, you know...
>
> private List<SomeType> _things = new List<SomeType>();
>
> [DataMember]
> public List<SomeType> Things
> {
> get { return _things; }
> }
>
> The old XmlSerializer used to understand this and play nicely but the
> DataContract serializer doesn't seem to want to.
>
> Any ideas? Am I missing an attribute somewhere?
>



Old 11-08-2006   #3 (permalink)
MrAnon
Guest


 

Re: Readonly collection support in DataContractSerializer?

Thanks Arkady,

I am aware of that option but I'm wondering if it's possible to
configure the DataContract Serializer to be happy with this...

Anyone?

Old 11-09-2006   #4 (permalink)
Arkady Frenkel
Guest


 

Re: Readonly collection support in DataContractSerializer?

Additionally : you can set empty setter to be it happy
Arkady

"MrAnon" <josh.twist@gmail.com> wrote in message
news:1163003829.126813.163320@f16g2000cwb.googlegroups.com...
> Thanks Arkady,
>
> I am aware of that option but I'm wondering if it's possible to
> configure the DataContract Serializer to be happy with this...
>
> Anyone?
>



Old 11-16-2006   #5 (permalink)
MrAnon
Guest


 

Re: Readonly collection support in DataContractSerializer?

But the serializer will add things to the collection that we ignored...
so my collection will always be emtpy


Arkady Frenkel wrote:

> Additionally : you can set empty setter to be it happy
> Arkady
>
> "MrAnon" <josh.twist@gmail.com> wrote in message
> news:1163003829.126813.163320@f16g2000cwb.googlegroups.com...
> > Thanks Arkady,
> >
> > I am aware of that option but I'm wondering if it's possible to
> > configure the DataContract Serializer to be happy with this...
> >
> > Anyone?
> >


Old 11-16-2006   #6 (permalink)
Arkady Frenkel
Guest


 

Re: Readonly collection support in DataContractSerializer?

BTW , you can ask additionally if that documented somewhere on
http://forums.microsoft.com/MSDN/Sho...D=118&SiteID=1
Arkady

"MrAnon" <josh.twist@gmail.com> wrote in message
news:1163677111.476397.14850@k70g2000cwa.googlegroups.com...
> But the serializer will add things to the collection that we ignored...
> so my collection will always be emtpy
>
>
> Arkady Frenkel wrote:
>
>> Additionally : you can set empty setter to be it happy
>> Arkady
>>
>> "MrAnon" <josh.twist@gmail.com> wrote in message
>> news:1163003829.126813.163320@f16g2000cwb.googlegroups.com...
>> > Thanks Arkady,
>> >
>> > I am aware of that option but I'm wondering if it's possible to
>> > configure the DataContract Serializer to be happy with this...
>> >
>> > Anyone?
>> >

>



Old 12-11-2006   #7 (permalink)
Sara Wong [MS]
Guest


 

RE: Readonly collection support in DataContractSerializer?

MrAnon,

The behavior for DataContractSerializer mentioned below is currently by
design. Using an empty setter, as mentioned later in the thread will result
in data lost during deserialization.

Thanks,
Sara

"MrAnon" wrote:

> Just getting to grips with the new (to me) DataContractSerializer
> through WCF and my class is failing to serialize because a [DataMember]
> doesn't have a setter. But there's a good reason for this - the
> property is a readonly collection, you know...
>
> private List<SomeType> _things = new List<SomeType>();
>
> [DataMember]
> public List<SomeType> Things
> {
> get { return _things; }
> }
>
> The old XmlSerializer used to understand this and play nicely but the
> DataContract serializer doesn't seem to want to.
>
> Any ideas? Am I missing an attribute somewhere?
>
>

 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: ReadOnly Ken Zhao [MSFT] Vista networking & sharing 0 11-04-2007 09:08 PM
setting a variable as readonly klumsy@xtra.co.nz PowerShell 4 10-27-2006 12:14 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50