[Mono-list] XSD -> classes -> deserialize not so easy after all

Athos Deterious gwehydd at gmail.com
Tue Nov 15 13:28:47 EST 2011

All mentioned files are located 

Hi All,

I'm completely new to Web Services and XSD's - I've primarily done 'Linq to

So I got this task of developing a Library application (in MonoTouch).
Sounded easy enough.

I started of by getting the "AlmaMessage.xsd" file and its documentation

Ok, I did a simple ">xsd AlmaMessage.xsd /classes" and got the
"AlmaMessage.cs" file.

I then made a console project in MonoDevelop and included all the files and
some test data in "Test.xml".

After a few test I made this primitive program :

using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using Schemas; // Namespace in the AlmaMessage.cs file

namespace aTestofXSDtoCS
	class MainClass
		public static void Main (string[] args)
			AlmaMessage am = new AlmaMessage();
			XmlSerializer s = new XmlSerializer(typeof(AlmaMessage));
			FileStream fs = new FileStream("Test.xml", FileMode.Open);
                        XmlReader reader = XmlReader.Create(fs);
			am  = (AlmaMessage) s.Deserialize(reader);


After a successful build I tried to run it but got the following :

/[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: There
is an error in XML document. ---> System.InvalidOperationException:
<AlmaMessage xmlns=''> was not expected
  at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot
(System.Xml.Serialization.XmlTypeMapping rootMap) [0x00066] in
  at System.Xml.Serialization.XmlSerializationReaderInterpreter.ReadRoot ()
[0x00028] in
  at System.Xml.Serialization.XmlSerializer.Deserialize
(System.Xml.Serialization.XmlSerializationReader reader) [0x0001c] in
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlSerializer.Deserialize
(System.Xml.Serialization.XmlSerializationReader reader) [0x00064] in
  at System.Xml.Serialization.XmlSerializer.Deserialize
(System.Xml.XmlReader xmlReader) [0x0002c] in
  at a.MainClass.Main (System.String[] args) [0x00029] in

Press any key to continue.../

This is where I got stuck ... no matter what I do I seem to go back to this
error ... now since I don't know much about XSD's, XML or Web Services I
can't get passed this point without more work then I have time for so could
someone help ?

Athos Deterious.

View this message in context: http://mono.1490590.n4.nabble.com/XSD-classes-deserialize-not-so-easy-after-all-tp4073570p4073570.html
Sent from the Mono - General mailing list archive at Nabble.com.

More information about the Mono-list mailing list