Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

A gold medal to the person who can tell me why this isnt working. FYI it has no inner exception text so its not helping me at all...

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

My innerexception is just Null. My error is: {"Object reference not set to an instance of an object."}

Here is my class:

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);
            }
        }




    }
}

If it helps, here is the other class it inherits from:

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));
            }
        }
    }
}

Does anyone have any idea, its driving me mad.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
233 views
Welcome To Ask or Share your Answers For Others

1 Answer

This doesn't look right:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...