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

  • Home
  • SEARCH
  • 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 4051164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:09:38+00:00 2026-05-20T14:09:38+00:00

All, I am trying to serialize and de-serialize a class and the de-serialization is

  • 0

All, I am trying to serialize and de-serialize a class and the de-serialization is failing. There are tons of similar threads, but I am unable to resolve this. I am getting the following error “There is an error in XML document (2, 2)” Inner expection “{” was not expected.”}”

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace XMLSerialization
{
 [System.Xml.Serialization.XmlRootAttribute(Namespace = "",
     IsNullable = false)] 
 public class Level
 {
  private String _name;
  private String _background;

  public Level() 
  {
   _name = "LEVEL_NAME";
   _background = "LEVEL_BACKGROUND_IMAGE";
  }

  [XmlAttribute("LevelName")]
  public String LevelName
  {
   get { return _name; }
   set { _name = value; }
  }

  [XmlAttribute("Background")]
  public String Background
  {
   get { return _background; }
   set { _background = value; }
  }
 }
}

This is the code I use for de-serialization. The serialization is happening fine but the de-serialization is not going through. I think that I am doing a trivial mistake but I am unable to solve this!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace XMLSerialization
{
 class Program
 {
  static void Main(string[] args)
  {
   Level oLevel1 = new Level();

   XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
   ns.Add("", ""); 
   XmlSerializer serializer = new XmlSerializer(typeof(Level));
   TextWriter textWriter = new StreamWriter("Level1.xml");
   serializer.Serialize(textWriter, oLevel1, ns);
   textWriter.Close();

   Level oLevel2 = new Level();
   XmlSerializer deserializer = new XmlSerializer(typeof(List<Level>));
   TextReader textReader = new StreamReader("Level1.xml");
   oLevel2 = (Level)deserializer.Deserialize(textReader);
   textReader.Close();
  }
 }
}
  • 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-05-20T14:09:39+00:00Added an answer on May 20, 2026 at 2:09 pm

    I think you need to change the line

    XmlSerializer deserializer = new XmlSerializer(typeof(List<Level>));
    

    To

    XmlSerializer deserializer = new XmlSerializer(typeof(Level));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load a html page through UIWebview.I need to disable all
If all tables I want to delete from have the column gamer_id can i
I am writing a query to fetch results for all the values in a
There doesn't seem to be any tried and true set of best practices to
I want to use a temp directory that will be unique to this build.
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
If I write a python script using only python standard libraries, using Python 2.6
I have a new web app that is packaged as a WAR as part
I am attempting to pull some information from my tnsnames file using regex. I
IE is giving me an undefined NAN when i try to view the calender...

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.