Deserialize object property with StringReader vs XmlNodeReader

后端 未结 1 714
小蘑菇
小蘑菇 2020-11-30 15:38

Why does XmlSerializer populate my object property with an XmlNode array when deserializing an empty typed element using XmlNodeReader

相关标签:
1条回答
  • 2020-11-30 16:04

    It looks like this is a very old XmlNodeReader bug that Microsoft have no intention of fixing. (Archived Microsoft Connect link here). I found a workaround on Lev Gimelfarb's blog here that adds namespaces to the reader's NameTable as prefixes are looked up.

    public class ProperXmlNodeReader : XmlNodeReader
    {
        public ProperXmlNodeReader(XmlNode node) : base(node)
        {
        }
    
        public override string LookupNamespace(string prefix)
        {
            return NameTable.Add(base.LookupNamespace(prefix));
        }
    }
    
    0 讨论(0)
提交回复
热议问题