Improvements to the XmlSerializer in Whidbey

From Doug Purdy's  PDC '03  talk:

 

  • The new imperative model for the XmlSerializer opens up the previously unsupported interface IXmlSerializable. With the Whidbey release, the interface is now fully supported and the broken type import feature is fixed.
  • The XmlSerializer dynamically generates code for helper types and compiles them into a temporary assembly on the fly. This is a very expensive operation that always happens the first time you instantiate an XmlSerializer instance for given type when a program runs. When the program shuts down, the XmlSerializer will clean up the temporary assembly and has to go through the (expensive) code generation and compilation step again. Whidbey will add a helper tool that will allow pregen these serialization helper types deploy them together with your application.
  • The XmlSerializer will support serialization of classes based on Generics.
Published Tuesday, October 28, 2003 7:33 PM by ChristophDotNet
Filed under: , ,

Comments

# re: Improvements to the XmlSerializer in Whidbey

Wednesday, October 29, 2003 5:23 AM by Frans Bouma
"The new imperative model for the XmlSerializer opens up the previously unsupported interface IXmlSerializable."
FINALLY!

At last we can reroute our ToXml() methods to a method that is understood by XmlSerializer so it can serialize our classes which are build with interfaces (because they have to be generic) and interfaces are a concept the XmlSerializer has never heard of...

# re: Improvements to the XmlSerializer in Whidbey

Wednesday, November 05, 2003 9:42 AM by Andrew Sharpe
I don't see a fix for serialization of objects that have interface properties. I can't see how anyone is using the XMLSerializer with this limitation.

# re: Improvements to the XmlSerializer in Whidbey

Friday, November 07, 2003 11:42 PM by Christoph
Andrew,

Serialization of interface properties is probably not a priority because it doesn't map to anything in the XSD type system.

There are also questions about how to embed enough type information about the interface in the serialized output in a schema valid way. Without that information how would you be able to deserialize it back?

It boils down to the fact that the XmlSerializer is not intended to flatten object graphs for persistent storage. It to translate between strongly typed XML documents and runtime objects.

Christoph

# re: Improvements to the XmlSerializer in Whidbey

Monday, February 02, 2004 2:46 AM by JohnBergman
We frequently serialize with interface objects. It requires you to create two sets of methods.. for example

public class MyClass : IMyClass
{
private MyObject m_oObject;

public MyObject OneToWriteToXml
{
get { return this.m_oObject; }
set { this.m_oObject=value; }
}


IMyObject IMyClass.OneToWriteToXml
{
get { return this.OneToWriteToXml; }
set { this.OneToWriteToXml=(MyObject)value }
}
}

My Interface methods simply 'thunk' to the classes public method. This allows you to use an interface as well as serialize.

If you need to serialize objects that are derived from other objects, I generally create an abstract base class, and make all the objects derived from it that I will be returning. As long as you have the objects listed in the XmlSerializers array, they appear to deserialize fine.


I think they should update the XmlSerializer/DeSerializer to handle the case where protected/private data is attributed with XmlAttribute/XmlElement to be put into the Serialized Xml as well.

John

# re: Santa (e.g. Bill G). For Christmas can I get control of the xml serialization process?

Wednesday, April 14, 2004 5:54 PM by TrackBack

# re: If I don't understand it, or it doesn't work the way I expect it to then it is broken

Monday, January 31, 2005 8:48 AM by TrackBack
As far as IXmlSerializable goes, in framework 1.0 and 1.1 it bears the following description:

# re: Improvements to the XmlSerializer in Whidbey

Tuesday, January 08, 2008 3:30 AM by kistov

<a href= http://index1.elurker.com >combining ceramics fused glass</a>

# re: Improvements to the XmlSerializer in Whidbey

Friday, December 05, 2008 8:28 PM by Semil

<a href= spiritez.com ></a>

Leave a Comment

(required) 
(required) 
(optional)
(required)