Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:22:29+00:00 2026-06-05T16:22:29+00:00

I am trying to read in an XML file that I have saved to

  • 0

I am trying to read in an XML file that I have saved to an IsolatedStorageFile using Serialize. When I try to read back the XML file in a try block it throws an exception at the Deserialization step. Am I doing something wrong? How can I fix this?

Bet Class:

public class Bet
{
    public String Amount { get; set; }
    public String Opponent { get; set; }
    public String Terms { get; set; }
    public int Result { get; set; }
    public String ResultColor { get; set; }

    public Bet(String amount, String opponent, String terms, int result, String rcolor)
    {
        this.Amount = amount;
        this.Opponent = opponent;
        this.Terms = terms;
        this.Result = result;
        this.ResultColor = rcolor;
    }
}

Save/Load Bet functions

public void SaveBets()
{
    List<Bet> bets = new List<Bet>();

    foreach (Bet item in openBetList)
        bets.Add(item);

    foreach (Bet item in closedBetList)
        bets.Add(item);

    // Write to the Isolated Storage
    XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
    xmlWriterSettings.Indent = true;

    using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Bets.xml", FileMode.Create))
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<Bet>));
            using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
            {
                serializer.Serialize(xmlWriter, bets);
            }
        }
    }
}

public void LoadBets()
{
    try
    {
        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Bets.xml", FileMode.Open))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List<Bet>));
                List<Bet> data = (List<Bet>)serializer.Deserialize(stream);

                if(data.Count > 0)
                    foreach (Bet item in data)
                    {
                        if (item.Result == 0)
                            openBetList.Add(item);
                        else
                            closedBetList.Add(item);
                    }
            }
        }
    }
    catch
    {
        //add some code here
    }
}

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:22:30+00:00Added an answer on June 5, 2026 at 4:22 pm

    What is the exception?

    As I can remeber you need a constructor without parameters for this…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really simple XML file that I'm trying to read, but I
I have an XML file that I'm trying to read from here , and
I'm trying to read existing xml file, that has duplicated namespace declarations. It is
I'm trying to read from an XML file and use that to populate a
I have an xml file(from federal government's data.gov) which I'm trying to read with
I have an XML file as follows, and I'm trying to read the content
I have been trying to read an xml file. I have to extract value
Hi there I have been trying to read an xml file with UTF strings,
Hello I am trying to read my xml document using xpath. I have been
I am trying to have PHP read an XML file and then convert it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.