2013-02-12 4 views
-2

Золотая медаль человека, который может сказать мне, почему это не работает. FYI это не имеет никакого внутреннего текста исключения поэтому его не помогает мне во всем ...XmlSerializer Предоставление исключения для исключения в C#

XmlSerializer x = new XmlSerializer(typeof(DownloadedSite)); 

Мой InnerException просто Null. Моя ошибка: { «Ссылка на объект не указывает на экземпляр объекта.»}

Вот мой класс:

namespace WayBackMachine.Business.Obj 
{ 
    using System; 
    using System.Xml.Serialization; 
    using System.Linq; 
    using System.Collections.Generic; 

    [Serializable] 
    [XmlRoot("DownloadedSite")] 
    public class DownloadedSite : ManagedObject 
    { 
     private SortableBindingList<SiteSource> sources;// = new SortableBindingList<SiteSource>(); 
     private SortableBindingList<SiteSource> links;// = new SortableBindingList<SiteSource>(); 
     private SortableBindingList<Page> pages;// = new SortableBindingList<Page>(); 
     private string name; 
     private string defaultSite; 

     public DownloadedSite() : base() 
     { 
      sources = new SortableBindingList<SiteSource>(); 
      links = new SortableBindingList<SiteSource>(); 
      pages = new SortableBindingList<Page>(); 
      name = ""; 
      defaultSite = ""; 
     } 

     [XmlArray("Sources")] 
     [XmlArrayItem("SiteSource", typeof(SiteSource))] 
     public SortableBindingList<SiteSource> Sources 
     { 
      get { return this.sources; } 
      set 
      { 
       this.CheckPropertyChanged<SortableBindingList<SiteSource>> 
       ("Sources", ref this.sources, ref value); 
      } 
     } 

     [XmlArray("Links")] 
     [XmlArrayItem("SiteSource", typeof(SiteSource))] 
     public SortableBindingList<SiteSource> Links 
     { 
      get { return this.links; } 
      set 
      { 
       this.CheckPropertyChanged<SortableBindingList<SiteSource>> 
       ("Links", ref this.links, ref value); 
      } 
     } 

     [XmlArray("Pages")] 
     [XmlArrayItem("Page", typeof(SiteSource))] 
     public SortableBindingList<Page> Pages 
     { 
      get { return this.pages; } 
      set 
      { 
       this.CheckPropertyChanged<SortableBindingList<Page>> 
       ("Pages", ref this.pages, ref value); 
      } 
     } 

     [XmlElement("SiteName")] 
     public string Name 
     { 
      get { return this.name; } 
      set 
      { 
       CheckPropertyChanged<string> 
       ("Name", ref this.name, ref value); 
      } 
     } 

     [XmlElement("DefaultSite")] 
     public string DefaultSite 
     { 
      get { return this.defaultSite; } 
      set 
      { 
       CheckPropertyChanged<string> 
       ("DefaultSite", ref this.defaultSite, ref value); 
      } 
     } 




    } 
} 

Если это помогает, вот другой класс наследует от:

namespace WayBackMachine.Business 
{ 
    using System.ComponentModel; 
    using System; 
    using System.Xml.Serialization; 

    [Serializable] 
    [XmlRoot("ManagedObject")] 
    public class ManagedObject : INotifyPropertyChanged 
    { 
     public event PropertyChangedEventHandler PropertyChanged; 

     protected bool CheckPropertyChanged<T>(string propertyName, ref T oldValue, ref T newValue) 
     { 
      if (oldValue == null && newValue == null) 
      { 
       return false; 
      } 
      if (oldValue == null && newValue != null || !oldValue.Equals((T)newValue)) 
      { 
       oldValue = newValue; 
       FirePropertyChanged(propertyName); 
       return true; 
      } 
      return false; 
     } 

     protected void FirePropertyChanged(string propertyName) 
     { 
      if (this.PropertyChanged != null) 
      { 
       this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
      } 
     } 
    } 
} 

Есть ли у кого-нибудь идеи, сводя меня с ума.

+0

В какой строке вы получаете исключение? –

+0

Вы сериализуете или десериализуете? –

+0

Какая строка является ошибкой? – baldric

ответ

1

Это выглядит не так:

[XmlArray("Pages")] 
[XmlArrayItem("Page", typeof(SiteSource))] <-- should be typeof(Page)? 
public SortableBindingList<Page> Pages 
+0

Для любви к Богу это все. –

0

В первую очередь проверьте узел существует, существует записать код

XmlNode XMLnode = voucharbrandnode.SelectSingleNode ("имя узла");

if (xmlNode != null) 
{ 
write some code 
} 
Смежные вопросы