XML Serialization

  • Thread starter Thread starter Tom
  • Start date Start date
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.
 
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.
 
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
 
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
 
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
 
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.
 
Back
Top