0

I have the following xml:

XML

I have the following C# class

C# GlobalClass

I am trying to convert the xml content into C# custom object like that:

string xmlFilePath = Android.OS.Environment.ExternalStorageDirectory.ToString() + "/Settings4/settings.xml";
XmlSerializer deserializer = new XmlSerializer(typeof(GlobalClass));
TextReader textReader = new StreamReader(xmlFilePath);
GlobalClass globalVariables;
globalVariables = (GlobalClass)deserializer.Deserialize(textReader);
textReader.Close();

But I get

There is an error in XML document 

on the line of code

globalVariables = (GlobalClass)deserializer.Deserialize(textReader);

I make GlobalClass inherit from Application because I want GlobalClass to be global that is to say I want to use its properties throughout all activities. What I'm doing wrong to recieve that error?

Profile2ForStack
  • 473
  • 2
  • 8
  • 16

1 Answers1

0

In your class put something like this [Serializable, XmlRoot("YourRoot")] When you work with deserialization it might not found.

From MSDN

The name of the XML root element that is generated and recognized in an XML-document instance. The default is the name of the serialized class.

NSKBpro
  • 373
  • 1
  • 14