XmlSerializer is not trustable

XmlSerializer is stupid in many ways..., it did cause me a lot of trouble.

1.       Normally we use it to serialize a class to xml stream by calling Serialize() method, it this  method  has several overloaded versions. When XmlSerializerNamespaces is specified as input parameter it is supposed to generate a prefix right before the xml tab, e.g. Serialize(Stream stream, Object o, XmlSerializerNamespaces namespaces ), but it does not always generate the expected result like <prefix:tagname..>. It could be caused by different .Net framework versions installed, but the inconsistent behavior cause a lot of tricky problems.

2.       System.Xml.Serialization.XmlElementAttribute is used to determine what the xml tag for current field is after serialization, for example.

Public  class DemoClass

{

Private string  m _Name;

System.Xml.Serialization.XmlElementAttribute(“FullName”)

Public string Name

{

                Get {return m_Name;}

                Set {m_Name =value;}

}

}

 

After serialization, the corresponding  xml tag for Name should be FullName, but XmlSerializer does not always output FullName, sometimes it will output Name directly. You also can find a tons of XmlSerializer related bug descriptions on internet, google it.

0
0
(请您对文章做出评价)
« 上一篇:BizTalk - How to create custom functoid.
» 下一篇:What happens if BizTalk artifacts are not GACed?
posted @ 2009-01-08 00:09 zhanqiangz(闲云野鹤) 阅读(90) 评论(0)  编辑 收藏 所属分类: VB.NET, CSharp