473,473 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

i get this error while deserializing..there is an error in xml document (0,0)

7 New Member
inner exception is root element is missing...plz help.Here is the code....
Expand|Select|Wrap|Line Numbers
  1.  public string SerializeObject(Object objToSerialize)
  2.         {
  3.             XmlSerializer ser = new XmlSerializer(objToSerialize.GetType());
  4.             StringWriter writer = new StringWriter(); 
  5.             ser.Serialize(writer, objToSerialize);       
  6.             writer.Close();
  7.             return writer.ToString();
  8.         } 
  9.  
Expand|Select|Wrap|Line Numbers
  1. public object DeSerializeAnObject(string xmlOfAnObject,Type ObjectType)
  2.         {
  3.             StringReader reader = new StringReader(xmlOfAnObject);
  4.             XmlSerializer ser = new XmlSerializer(ObjectType);
  5.             XmlTextReader XmlReader = new XmlTextReader(reader);
  6.             try
  7.             {
  8.                 Object ObjDeserialize = new Object();
  9.                 ObjDeserialize = (Object)ser.Deserialize(reader);
  10.                 return ObjDeserialize;
  11.             }
  12.             catch (Exception ex)
  13.             {
  14.                 throw new Exception(ex.StackTrace);
  15.             }
  16.  
  17.             finally
  18.             {
  19.                 XmlReader.Close();
  20.                 reader.Close();
  21.             }
  22.         }
  23.  
Jun 9 '10 #1
4 8811
Plater
7,872 Recognized Expert Expert
Correct the line to this:
ObjDeserialize = (Object)ser.Deserialize(XmlReader);
Jun 9 '10 #2
khushboosoni
7 New Member
Thanks.Deserialization works now,but i have another problem.When i assign the deserialized object i get the default values of the object,not the updated values.
Jun 10 '10 #3
khushboosoni
7 New Member
XmlTextReader XmlReader = new XmlTextReader(strReader);

Is it because of this line that while deserializing the object returned has default values and not what we set it.
While debugging the code, XmlReader is set to none.
Jun 10 '10 #4
Plater
7,872 Recognized Expert Expert
Hmmm, I just ran this test:
Expand|Select|Wrap|Line Numbers
  1. List<string> fnn = new List<string>();
  2.             fnn.Add("fred");
  3.             fnn.Add("bill");
  4.             string s = SerializeObject(fnn);
  5.             object o = DeSerializeAnObject(s, fnn.GetType());
  6.             List<string> retfnn = (List<string>)o;
  7.  
And retfnn had the same two values as fnn
Jun 10 '10 #5

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

Similar topics

7
by: Roberta McGervey | last post by:
I have the following code: <Script LANGUAGE=vbscript RUNAT=Server> for i =0 to document.form1.elements.count-1 response.write "test" next
7
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var...
6
by: effendi | last post by:
I have a page with checkboxes generated by a script. Users are suppose to select the checkboxes and click on a button to process their selection. The codes work fine except when I only have one...
1
by: Andrew Phillipo | last post by:
I have some code that works everywhere but IE5.0, including IE5.5. Here is a snippet of where the code seems to go wrong: Location.prototype.change = function(current) { this.current = current;...
0
by: Riley Phelps | last post by:
When I use the XML Serializer in the following example, the first Serialize (with the class Pets) works, but the second (with the cplaa Pets2) fails. Which arrtubute nedds to be applied to make the...
3
by: Raed Sawalha | last post by:
Hello when I serialize an object an error generated using this function public string SerializeObject(object oClassObject,System.Type oClassType) { XmlSerializer oSerializer = new...
10
by: robert d via AccessMonster.com | last post by:
I have a global error handler that up until today has been working flawlessly. Let me first provide the relevant code **************************************************************** On Error...
7
by: Diogenes | last post by:
Hi All; Two links here, exactly the same js code. Forms are slightly different. This works in both FF and IE7 http://68.147.197.6/calgarydj/sampleA.htm This one FAILS in IE7 (only) with...
0
Sakalicek
by: Sakalicek | last post by:
Hi all, I have following problem in my application. I have Web Service and project which uses methods from this Web Service. I created proxy WsProxy by wsdl.exe and put it into that project. But...
0
by: dgil2004 | last post by:
I am a real newbie when it comes to scripting, coding, etc We have a site were people go and load text documents. I can load the text document fine with no problems. But someone from another...
0
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,...
0
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...
0
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.