Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Serializer and Deserialize

Status
Not open for further replies.

gplusplus

Programmer
Jan 17, 2007
30
US
I have wrote a program that can serialize and deserialize from xml to a class obj and vice versa. It works most of the time but every once in a while it bombs out giving me an exception that is "TypeLoadException" on this line...

Code:
 XmlSerializer xml_serializer = new XmlSerializer(typeof(UserPreferences));
its totally random when it happens and i have it set to retry if it fails and sometimes it retrys successfully and sometimes it just keeps failing. i would say i get this exception 5% of the time. i just want to know why its throwing this exception and howto fix:) THANKS ALL!!!

here is my userpref class

Code:
   [XmlRoot("Nelson")]
    public class UserPreferences
    {
        [XmlElement("properties")]
        public UserProperties properties;

        public UserPreferences()
        {
            this.properties = new UserProperties();
        }

        public UserPreferences(UserProperties properties)
        {
            this.properties = properties;
        }
    }
 
    public class UserProperties
    {
        [XmlElement("defaultSourceXML")]
        public string default_input_xml;
        
        [XmlElement("showFileSelection")]
        public string show_source_selection;
        
        [XmlElement("timeFormat")]
        public string time_format;
        
        [XmlElement("checkUpdates")]
        public string check_updates;

        public UserProperties()
        {
            this.default_input_xml = "None";
            this.show_source_selection = "False";
            this.time_format = "hh:mm t";
            this.check_updates = "False";
        }

        public UserProperties(string default_input_xml, string show_source_selection, string time_format, string check_updates)
        {
            this.default_input_xml = default_input_xml;
            this.show_source_selection = show_source_selection;
            this.time_format = time_format;
            this.check_updates = check_updates;
        }
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top