可以告诉我为什么这不起作用的人的金牌。仅供参考,它没有内部异常文本,所以它根本没有帮助我......
XmlSerializer x = new XmlSerializer(typeof(DownloadedSite));
我的内心异常只是空。我的错误是:{“对象引用未设置为对象的实例。”}
这是我的课:
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));
}
}
}
}
有没有人有任何想法,它让我发疯。