なぜこれが機能しないのかを教えてくれる人への金メダル。参考までに、内部例外テキストがないため、まったく役に立ちません...
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));
}
}
}
}
誰かが何か考えを持っていますか、それは私を怒らせます。