Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.


Go Back   Vista Forums > Misc Newsgroups > Indigo

RB

Vista - Readonly collection support in DataContractSerializer?

 
 
11-08-2006   #1
MrAnon


 
 

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?


My System SpecsSystem Spec
11-08-2006   #2
Arkady Frenkel


 
 

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?
>



My System SpecsSystem Spec
11-08-2006   #3
MrAnon


 
 

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?

My System SpecsSystem Spec
11-09-2006   #4
Arkady Frenkel


 
 

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?
>



My System SpecsSystem Spec
11-16-2006   #5
MrAnon


 
 

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?
> >


My System SpecsSystem Spec
11-16-2006   #6
Arkady Frenkel


 
 

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?
>> >

>



My System SpecsSystem Spec
12-11-2006   #7
Sara Wong [MS]


 
 

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?
>
>

My System SpecsSystem Spec
 

RB


Thread Tools


Similar Threads for: Readonly collection support in DataContractSerializer?
Thread Forum
Database is readonly General Discussion
RE: ReadOnly Vista networking & sharing
setting a variable as readonly PowerShell


Vista Forums 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 Ltd