473,779 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserialization problem --> InvalidOperatio nException "obect xmlns=> was not expected

3 New Member
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.InvalidO perationExcepti on 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
2 12625
snowie
3 New Member
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
emil
1 New Member
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

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

Similar topics

3
6014
by: Ben Engber | last post by:
I'm trying to serialize/deserialize an object in SOAP-encoded form. I'm using the code below. Serialization succeeds fine, but when I try to deserialize I get an exception. Can anyone tell me how I can deserialize an object which has been serialized this way? Do I need to do something special with an XmlReader? (I don't have access to the underlying objects, so SoapFormatter is not an option for me.) Thanks,
2
9452
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data. Actually, second time I do a deserialization, the data from XML is fed directly to an object. The problem I am experiencing is the error at the second reading attempt, and error description implies that reader is winded to the end of the XML and...
4
59330
by: Shailendra Batham | last post by:
Hi guys,Does any1 know what this error is all about, what I am trying to do is deserialize a XML, below is my code, let me know what I am doing wrongpublic class test{xin = "<?xml version='1.0' encoding='UTF-8'?><InSession><PassWord>foo</PassWord><UserName>foo@foo.com</UserName></InSession>";XmlSerializer serializer = new XmlSerializer(typeof(cXmlBS));XmlTextReader tr = new XmlTextReader(new System.IO.StringReader(xin));cXmlBS cx =...
4
2967
by: pei_world | last post by:
I have followed a example from a book exactly, but it seems not working at all. can anyone tell me what is going on? ========= Global.asax.cs ============ public static Entry LoadEntry(String filename) { //construct the path
3
9795
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the response. As a result of seraching news groups I guessed that the SOAP response defines an array element in a way that causes the dotnet deserialization routines to put the content in a generic object array (object) BUT the content is supposed to...
6
2084
by: Marcus | last post by:
I have a couple of classes looking like this: ======================================== public class AdminSettingsData { public string adminSettingsPath; public string adminSettingsFile; public string usersSettingsPath;
1
1609
by: John Smith | last post by:
This is what I am trying to do: FileStream fs = new FileStream("C:\\request1.xml", FileMode.Open); XmlSerializer x = new XmlSerializer(typeof(PodpisaniDokumentTip)); PodpisaniDokumentTip doc = (PodpisaniDokumentTip)x.Deserialize(fs); And this is my class (auto generated from WSDL):
2
8687
by: Steve Richter | last post by:
I would like to use display:inline and other CSS attributes to build an entry form. Where the heading to the left of the text box is always a set width. It is not working so I am experimenting with two divs to get them to render side by side: <div style="width:12em;border: 2px solid #EFCE8C; padding: 0.5em;display:inline;">abc</div> <div style="width:12em;border: 2px solid #EFCE8C; padding:
3
8477
by: Stubbie | last post by:
have an object (InputFile) that I am able to successfully serialize to XML and deserialize back into the object through an IXmlSerializable interface. Now I'm trying to serialize a List<InputFile> to XML. I'm using the following code: XmlSerializer s = new XmlSerializer(typeof(List<Inputs.InputFile>)); TextWriter w = new StreamWriter("c:\\out.xml"); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", "");...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.