XmlSerializer

  • Thread starter Thread starter Wayne
  • Start date Start date
W

Wayne

I have the following code, this is a form. When I get to the second line I
am receiving "Additional information: There was an error reflecting type
'WindowsApplication3.Form1'." Am I just missing something here? It's been a
long day so it is possible.

Type type = this.GetType();

XmlSerializer serializer = new XmlSerializer(type);


--
Thanks
Wayne Sepega
Jacksonville, Fl



"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
 
hmmm... is the Form class serializable?
Does the error message give more details (i.e. have you tried printing
out the Exception.ToString() ?) I think I've seen that exception when I
was trying to serialize un-serializable things or one of the fields of
the serializable class was of an un-expected type (XmlInclude helped
with this second issue).

HTH,
F.O.R.
 
When dealing with complex classes and serializing them. Sometimes it is
easier to create a DataTransferObject (DTO) which is a simple class to
reflects only the public fields you want to serialize and make sure those
fields are serializable.

public class XmlForm
{
public string Field1;
public int Field2;

public XmlForm() {}
}

Then create a helper method that copies the required info (doing any
conversions) to a new DTO and just serialize the DTO. This also helps keep
seperation of what your transfering/storing and your complex gui/business
logic classes.
 
Wow, such a simple Idea, but yet it didn't occur to me to do so. The
Exception.ToString() has this in it:

Cannot serialize member System.ComponentModel.Component.Site of type
System.ComponentModel.ISite because it is an interface.

So Guess the form isn't fully able to be serialized due to the interface
exposed. Well that answers why, now I can delete the test app.

Thanks for you help.
 
Back
Top