Serialization problem with late binding

S

Sacha

I'm having trouble serializing some of my classes when using late binding.
When I don't use late binding, it works fine. MyClass inherit from an
abstract class called
AbsMyClass.

If I do the following, it works fine:
#BEGIN
public static void Write( string fileName ){
MyClass myClass = null;
XmlSerializer xmlSerializer = null;
Stream stream = null;

myClass = new MyClass();

xmlSerializer = new XmlSerializer( myClass.GetType() );
stream = new FileStream(fileName, FileMode.Create,
FileAccess.Write, FileShare.None);

xmlSerializer.Serialize(stream, gen);
stream.Close();
}
#END

If I do the following, I get a error msg

#BEGIN
public static void Write( string fileName ){
AbsMyClass myAbsClass = null;
XmlSerializer xmlSerializer = null;
Stream stream = null;

//This will get a pre-created myAbsClass using reflection
// The GetAbsClass is used in many other places in my code and it
// correctly return a pre-created class of the right type.
myAbsClass = GetAbsClass("MyFullClassName");

xmlSerializer = new XmlSerializer(
myAbsClass.GetType() );
stream = new FileStream(fileName, FileMode.Create,
FileAccess.Write, FileShare.None);

xmlSerializer.Serialize(stream, gen);
stream.Close();
}
#END

#ERROR

ex : There was an error generating the XML document.
stack trace :
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Obje
ct o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Obje
ct o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object
o,
XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object
o)
#END_ERROR


Tks in advance.
 
N

Nicholas Paldino [.NET/C# MVP]

Sacha,

Can you give the message that comes with the Exception?
 

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