HmXa
HmXa

Reputation: 77

Passing different Objects from XmlSerializer function

How can we pass different Object from a given function.

 static public void SerializeToXML(FbTextView p)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(FbTextView));
        TextWriter textWriter = new StreamWriter(@"D:\movie.xml");
        serializer.Serialize(textWriter, p);
        textWriter.Close();
    }

now the problem is that when I try to pass two or more then two objects like this:

  static public void SerializeToXML(FbTextView p,FbTextField q)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(FbTextView));
        XmlSerializer Serializer = new XmlSerializer(typeof(FbTextField));
        TextWriter textWriter = new StreamWriter(@"D:\movie.xml");
        serializer.Serialize(textWriter, p);
        textWriter.Close();
    }

it throw error: XMLParse Exception Was unhandled. and the inner exception is : "There was an error reflecting type 'FBformBuilder.FbTextField" thanks !

Upvotes: 2

Views: 1019

Answers (2)

Dmitrii Dovgopolyi
Dmitrii Dovgopolyi

Reputation: 6301

inner exception:

The type for XmlElement may not be specified for primitive types.

Remove [XmlElement(Type)] attribute from FbTextField Value field

Upvotes: 0

Marc Gravell
Marc Gravell

Reputation: 1063569

The problem will be fully detailed in the inner exceptions; try:

try {
    // ... your code
} catch(Exception ex) {
    while(ex != null) {
        Trace.WriteLine(ex.Message);
        ex = ex.InnerException;
    }
    throw;
}

then look at all the .Messages that get logged. One of these will tell you the exact problem. For example, it could be something like:

  • no public parameterless constructor
  • not a public type
  • invalid sub-class
  • duplicated/ambiguous element/namespace

or something similar

Upvotes: 1

Related Questions