By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,520 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

Deserialization problem --> InvalidOperationException "obect xmlns=> was not expected

P: 3
I have a simillar problem to what others have had before me. I just can't find the solution in any earlier post here at the scripts (or any other forum).

I am calling a web service that returns a string, the string is an object serialized into XML. The XML returned could look like:

Expand|Select|Wrap|Line Numbers
  1.  <object><name>Safir.Vehicles.Vehicle</name><instance>0</instance><members><member><name>Callsign</name><value></value></member><member><name>Identity</name><value>Safir.Vehicles.Enum.Identity.Friend</value></member><member><name>Transient</name></member><member><name>VehicleID</name><value></value></member></members></object> 
  2.  
This is the class for the object:
Expand|Select|Wrap|Line Numbers
  1.  
  2. [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
  3. [System.SerializableAttribute()] 
  4. [System.Diagnostics.DebuggerStepThroughAttribute()]
  5. [System.ComponentModel.DesignerCategoryAttribute("code")]
  6. [System.Xml.Serialization.XmlRootAttribute("object", IsNullable=false)]
  7. public partial class ctObject {
  8.  
  9. private string nameField;
  10.  
  11. private object itemField;
  12.  
  13. private ctObjectMember[] membersField;
  14.  
  15. /// <remarks/>
  16. public string name {
  17. get {
  18. return this.nameField;
  19. }
  20. set {
  21. this.nameField = value;
  22. }
  23. }
  24.  
  25. /// <remarks/>
  26. [System.Xml.Serialization.XmlElementAttribute("instance", typeof(string), DataType="integer")]
  27. [System.Xml.Serialization.XmlElementAttribute("instanceRef", typeof(ctReference))]
  28. public object Item {
  29. get {
  30. return this.itemField;
  31. }
  32. set {
  33. this.itemField = value;
  34. }
  35. }
  36.  
  37. /// <remarks/>
  38. [System.Xml.Serialization.XmlArrayItemAttribute("member", IsNullable=false)]
  39. public ctObjectMember[] members {
  40. get {
  41. return this.membersField;
  42. }
  43. set {
  44. this.membersField = value;
  45. }
  46. }
  47. }
  48.  
  49. I try to deserialize the XML string like this:
  50.  
  51. namespace getEntity_Client
  52. {
  53.  
  54. public enum douRootTypes { douObject };
  55. public enum douTypes { valueType, memberType, parameterType, createRoutinesType };
  56.  
  57. public class Program
  58. {
  59.  
  60. public static void Main(string[] args)
  61. {
  62. Program prgm = new Program();
  63. prgm.consoleApp();
  64. }
  65. public void consoleApp()
  66. {
  67. ctObject douObject = new ctObject();
  68.  
  69.  
  70. get_Entity getEntityService = new get_Entity();
  71. Console.WriteLine("Reading vehicle from web service...");
  72. //Invoke the web service call. Returns object serialized to XML 
  73. string strXMLEntity = getEntityService.getVehicle(0);
  74.  
  75. //The deserializing part
  76. XmlSerializer ctObjectSerializer = new XmlSerializer(typeof(ctObject));
  77. StringReader stream = null;
  78. XmlTextReader reader = null;
  79. stream = new StringReader(strXMLEntity); // read xml data
  80. reader = new XmlTextReader(stream); // create reader
  81.  
  82. this.RootType = douRootTypes.douObject;
  83. douObject = (ctObject)ctObjectSerializer.Deserialize(reader);
  84. ctObject douO = douObject;
  85. ....
  86. ...
  87. }
  88. }
  89.  
  90. The program throws the error in the second line from the end --> douObject = (ctObject)ctObjectSerializer.Deserialize(reader);
  91.  
  92.  
The error is: System.InvalidOperationException was unhandled
Message="There is an error in XML document (1, 2)."
InnerException: { "<object xmlns=>" was not expected." }

I don't get it. In the class def. there is the serializable definition, as well as the root element definition. Why does my serializer not connect ctObject with object ?

Help much appreciated --> totally stuck right now... :-(

Thanks in advance,

Erik Näslund
Aug 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: 3
I solved this problem myself.

I specified the name space (xmlns) in the serialized XML.
So that the name spaces agreed.

/Erik
Aug 13 '06 #2

P: 1
I solved this problem myself.

I specified the name space (xmlns) in the serialized XML.
So that the name spaces agreed.

/Erik
Erik can You illustrate me with more details ?bec i got the same crash as u did.
i appreciate if you help me.
How did you specify the name space exactly?
if you write code sample it can help for my solution as well
thanks
Aug 16 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.