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 9019803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:51:46+00:00 2026-06-16T04:51:46+00:00

I have the following class: [Serializable] public class SerialAssassin { public Hero hero; public

  • 0

I have the following class:

[Serializable]

public class SerialAssassin
{
    public Hero hero;
    public Point heroPB;
    public Boss boss;
    public Point bossPB;
    public Attack attack;
    public Point attackPB;
    public HPMeter bossHP;
    public Point bossHPPB;
    public PPMeter heroPP;
    public Point heroPPPB;

    public Rectangle bossRect;
    public Rectangle attackRect;

    public int heroState;
    public int stepRate;
    public int attackDirection;
    public int attackLoop;
    public int contadorPaso;
    public int contadorPasoBoss;
    public int bossTop, bossLeft;
    public int bossState;
    public int bossHealth;
    public int bossHPCap;
    public int opa;
    public int battlesWon;
    public int mainBossCounter;
    public int ppleft;
    public bool paso;
    public bool inStadium;
    public bool fading;
    public bool fightingMainBoss;
    public bool fainted;
    public string currentPokemon;
}

I’m having problems reading the data from the XML, which was written as follows:

XmlSerializer serializer = new XmlSerializer(typeof(SerialAssassin));
TextWriter textWriter = new StreamWriter(@"..\..\Resources\saveState.xml");
serializer.Serialize(textWriter, serial);
textWriter.Close();

From there, I don’t quite know how to read the data. Plus the fact that the XML doesn’t serialize the objects of Hero, Boss, Attack, HPMeter, PPMeter.

Hero class:

public class Hero
    {

        int state = 0;
        int x, y;
        string path;
        Image img;


        //methods
    }

I’d be grateful if you would be so kind as to explain to me how to load those objects/primitives and then use them.

  • 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-16T04:51:47+00:00Added an answer on June 16, 2026 at 4:51 am

    IIRC, the XmlSerializer checks for properties, not fields. (I think it can use public fields, but you really ought to switch to properties anyway) In addition, classes do not need to be marked as Serializable. (Serializable is used for others such as binary and SOAP serializers)

    Replace your fields with properties with public getters and setters. In addition, make sure your other classes (such as Hero, Point, Boss) are all also serializable according to XmlSerializer‘s rules:

    public class SerialAssassin
    {
        public Hero hero { get; set; }
        public Point heroPB { get; set; }
        public Boss boss { get; set; }
        public int heroState { get; set; }
        ...
    

    To deserialize, use its Deserialize method (http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.deserialize.aspx):

    Stream xmlInputStream = ... //get your file stream, or TextReader, or XmlReader
    XmlSerializer deserializer = new XmlSerializer(typeof(SerialAssassin));
    SerialAssassin assassin = (SerialAssassin)deserializer.Deserialize(xmlInputStream)
    

    EDIT: Looking at your sample Hero class, it’s not serializing any of its values because you have declared them all to be private. Make them public instead.

    public class Hero
    {
        public int state {get; set; }
        public int x { get; set; }
        public int y { get; set; }
        public string path { get; set; }
    
        [XmlIgnore]
        public Image img { get; set; }
    }
    

    I suspect that Image will not be serializable, so you may want to store the image’s file path (or some other identifying information) so you can save/load it. [XmlIgnore] will instruct the XmlSerializer to ignore that property so it doesn’t fail during serialization/deserialization.

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

Sidebar

Related Questions

Suppose I have the following 2 entities: @Entity public class Person implements Serializable {
I have the following mapping: @Entity @Table(name = Prequalifications) public class Prequalification implements Serializable
I have the following types [Serializable, XmlType(Namespace=http://mycompany/foo] public sealed class Limit { [XmlElement(ElementName=Value1)] public
I have the following classes [Serializable()] public class ColumnList { public ColumnList() { ListOfColumns
I have the following Java class: public class GetCardInfoRequest implements RequestBase, java.io.Serializable{ public String
I have the following object: [Serializable] public class ExampleImage { public int ID {
If I have the following code [Serializable] public abstract class ValidatedCommandArgs { } public
Have the following structure [Serializable] public class Parent { public int x = 5;
Ok, I have the following code. public class MyProgressBar extends JPanel implements MyData, Serializable
I have the following class signature and ClientEventSourc implements Serializable : public class Grid

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.