Золотая медаль человека, который может сказать мне, почему это не работает. 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));
}
}
}
}
Есть ли у кого-нибудь идеи, сводя меня с ума.
В какой строке вы получаете исключение? –
Вы сериализуете или десериализуете? –
Какая строка является ошибкой? – baldric