我将Web应用程序/解决方案从.NET 3.5升级到4.5.2。并且在将XML反序列化为对象时遇到了问题(没有编译问题)。自.Net 2.0以来,该应用程序的先前版本在过去的12年中没有遇到任何问题。在运行时,CallStack显示以下错误。经过广泛的谷歌搜索后,似乎我必须添加Add(),但我无法弄清楚它在升级到.NET 4.5.2之后的容量和位置以及为什么停止工作。向Map和/或MapEntry添加空Add(对象obj)并不是一个技巧。我花了很多时间,感谢任何帮助!
[InvalidOperationException]:要进行XML可序列化,从IEnumerable继承的类型必须在其继承层次结构的所有级别都具有Add(System.Object)的实现。 System.Xml.XPath.XPathNodeIterator未实现Add(System.Object)。 [InvalidOperationException]:反映字段mapItems时出错 [InvalidOperationException]:存在反映类型Framework.Common.Configuration.StructuredSettings.Map的错误 [InvalidOperationException]:反映类型Framework.Reporting.ReportConfig
时出错
public class StructuredSettings
{
public class Map
{
public Map() {}
public Map (params StructuredSettings.MapEntry[] items)
{
mapItems = items;
}
public MapEntry[] mapItems;
}
public abstract class MapEntry : IComparable
{
public MapEntry() {}
protected MapEntry(string key) { m_Key = key;}
// IComparable implementation
public int CompareTo(object obj)
{
MapEntry party = obj as MapEntry;
if (party == null)
throw new ArgumentException("Bla Bla", "obj");
return String.Compare(m_Key, party.m_Key);
}
}
//trying to de-serialize the XML into object. Get errors here at run time
public static XmlSerializer GetMapInstanceXmlSerializer(StructuredSettings.TypedTarget target)
{
XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();
attrOverrides.Add(typeof(StructuredSettings.Map), "mapItems",
GetArrayAttributes(target.MapItemType, target.ItemElementName));
XmlAttributes rootAttrs = new XmlAttributes();
rootAttrs.XmlRoot = new XmlRootAttribute(target.FieldElementName);
attrOverrides.Add(typeof(StructuredSettings.Map), rootAttrs);
return new XmlSerializer(target.FieldType, attrOverrides);
}
}
//Report Configuration is being initialized at run time, but break point never stops here
public class ReportConfig : StructuredSettings.MapEntry
{
public ReportConfig()
{
//original code does not have a constructor, but i tried adding to no vail
}
[XmlAttribute("Title")]
public string m_Title;
//many other attributes go here
[XmlElement("RenderingInfoWrap")]
public XmlDocument m_xmlRenderingInfo;
public XPathNodeIterator RenderingInfoNodeSet
{
get
{
if (m_xmlRenderingInfo == null)
return null;
return new XPathDocument(new XmlNodeReader(m_xmlRenderingInfo)).CreateNavigator().Select(@"*[1]");
}
}
}
// 30,31,32 31 MyUserName输入 何顾问 30,32 何顾问 HO_Consultant..fw_HOCList 总是 -1 (所有) HO_Consultant..rpt_InventorySummaryMultiHOC 何顾问 总开业数 总结算 总过去的日记 发生的总数 }