XML Serialization

T

Tom

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.
 
F

Family Tree Mike

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.
 
M

Michael Justin

Can anybody out there explain why I can't serialize an object to XML if
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
 
M

Michael Justin

Can anybody out there explain why I can't serialize an object to XML if
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
 
M

Michael Justin

Can anybody out there explain why I can't serialize an object to XML if
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
 
T

Tom

Ah yes ...

Thanks guys.


Family Tree Mike said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top