簡體   English   中英

XmlSerializer拋出異常“System.InvalidOperationException”

[英]XmlSerializer Throwing Exception “System.InvalidOperationException”

我有一個復雜的對象類用戶Info,它包含另一個類對象的列表。
復雜的對象:

[Serializable]
public class MESServerCluster 
{
    [XmlArray("MesServers")]
    public List<MESServer> MesServers { get; set; }
    public MESServerCluster() {}
}

Subentity對象:

[Serializable]
public class MESServer     {
    [System.Xml.Serialization.XmlIgnore()]
    public string NBLVIP { get; set; }

    public string ServerDomain { set; get; }
    public string ServerIPAddress { set; get; }
    public string ServerUsername { get; set; }
    public string ServerPassword { set; get; }

    [System.Xml.Serialization.XmlIgnore()]
    private Win32_Process wmi;

      public Win32_Process WMI
      {
          get
          {
              return wmi;
          }
          private set
          {
              wmi = value;
          }
      }

    public MESServer() { }

     public MESServer(string serverdomain, string serveripaddress, string serverusername, string serverpassword)
     {
          this.ServerDomain = serverdomain;
          this.ServerIPAddress = serveripaddress;
          this.ServerUsername = serverusername;
          this.ServerPassword = serverpassword;
      }

      public void InitWMI()
      {
          try
          {
           this.WMI = new Win32_Process(this.ServerDomain, this.ServerIPAddress, this.ServerUsername, this.ServerPassword);
          }
          catch (Exception ex){
              throw ex;
          }
      }

代碼拋出異常:XmlSerializer xmldes = new XmlSerializer(typeof(MESServerCluster));

如果將[System.Xml.Serialization.XmlIgnore()]屬性放入Win32_Process 字段 ,請將此屬性也放入Win32_Process 屬性中 順便說一句,您的異常消息在此處發布應該很重要。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM