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 > .NET General

Vista - XML Serialization

Reply
 
Old 04-15-2008   #1 (permalink)
Tom


 
 

XML Serialization

OK,

I have an object that I would like to serialize to an XML file. I can do
that successfully, but if I modify the object to have a constructor that
takes parameters, I get the following error message:

Object cannot be serialized because it does not have a parameterless
constructor

While this error message makes perfectly clear what the problem is, I still
don't understand why this is a problem. My google skills seem to be lacking
today too.

Can anybody out there explain why I can't serialize an object to XML if it
has a constructor that has parameters?

Thanks.


My System SpecsSystem Spec
Old 04-16-2008   #2 (permalink)
Family Tree Mike


 
 

RE: XML Serialization

I believe it is as simple as "How would the system know which elements to
feed to the constructor?".

By the way, having both an parameterless constructor as well as the one you
want with parameters is permitted.

"Tom" wrote:
Quote:

> OK,
>
> I have an object that I would like to serialize to an XML file. I can do
> that successfully, but if I modify the object to have a constructor that
> takes parameters, I get the following error message:
>
> Object cannot be serialized because it does not have a parameterless
> constructor
>
> While this error message makes perfectly clear what the problem is, I still
> don't understand why this is a problem. My google skills seem to be lacking
> today too.
>
> Can anybody out there explain why I can't serialize an object to XML if it
> has a constructor that has parameters?
>
> Thanks.
>
My System SpecsSystem Spec
Old 04-16-2008   #3 (permalink)
Michael Justin


 
 

Re: XML Serialization

> Can anybody out there explain why I can't serialize an object to XML if
Quote:

> it has a constructor that has parameters?
If there is *only* a constructor that takes parameters, the receiver of
the serialized object will need values for the parameters and pass them
to it in order to create an instance. See the problem?

Best Regards
--
Michael Justin
SCJP, SCJA
betasoft - Software for Delphiâ„¢ and for the Javaâ„¢ platform
http://www.mikejustin.com - http://www.betabeans.de
My System SpecsSystem Spec
Old 04-16-2008   #4 (permalink)
Michael Justin


 
 

Re: XML Serialization

> Can anybody out there explain why I can't serialize an object to XML if
Quote:

> it has a constructor that has parameters?
If there is *only* a constructor that takes parameters, the receiver of
the serialized object will need values for the parameters and pass them
to it in order to create an instance. See the problem?

Best Regards


--
Michael Justin
SCJP, SCJA
betasoft - Software for Delphiâ„¢ and for the Javaâ„¢ platform
http://www.mikejustin.com - http://www.betabeans.de
My System SpecsSystem Spec
Old 04-16-2008   #5 (permalink)
Michael Justin


 
 

Re: XML Serialization

> Can anybody out there explain why I can't serialize an object to XML if
Quote:

> it has a constructor that has parameters?
If there is *only* a constructor that takes parameters, the receiver of
the serialized object will need values for the parameters and pass them
to it in order to create an instance. See the problem?

Best Regards
--
Michael Justin
SCJP, SCJA
betasoft - Software for Delphiâ„¢ and for the Javaâ„¢ platform
http://www.mikejustin.com - http://www.betabeans.de
My System SpecsSystem Spec
Old 04-16-2008   #6 (permalink)
Tom


 
 

Re: XML Serialization

Ah yes ...

Thanks guys.


"Family Tree Mike" <FamilyTreeMike@xxxxxx> wrote in
message news:8039A762-8494-41AF-9E06-711973EF0703@xxxxxx
Quote:

>I believe it is as simple as "How would the system know which elements to
> feed to the constructor?".
>
> By the way, having both an parameterless constructor as well as the one
> you
> want with parameters is permitted.
>
> "Tom" wrote:
>
Quote:

>> OK,
>>
>> I have an object that I would like to serialize to an XML file. I can do
>> that successfully, but if I modify the object to have a constructor that
>> takes parameters, I get the following error message:
>>
>> Object cannot be serialized because it does not have a parameterless
>> constructor
>>
>> While this error message makes perfectly clear what the problem is, I
>> still
>> don't understand why this is a problem. My google skills seem to be
>> lacking
>> today too.
>>
>> Can anybody out there explain why I can't serialize an object to XML if
>> it
>> has a constructor that has parameters?
>>
>> Thanks.
>>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Serialization optimization .NET General


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

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