Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grrr! Darn thing won't deserialize
Message
 
To
31/08/2003 08:05:56
Keith Payne
Technical Marketing Solutions
Florida, United States
General information
Forum:
ASP.NET
Category:
SOAP
Miscellaneous
Thread ID:
00824911
Message ID:
00824931
Views:
27
This message has been marked as the solution to the initial question of the thread.
Hi Keith,

You need to set the memory stream position back to 0 before you attempt to deserialize. The problem is that the position is still sitting at the end.

>I'm getting an error - "The root element is missing." when attempting to deserialize from a memory stream into an object. What is driving me nuts is that I tested by saving the stream to a file right before serializing the object, and then saving the stream to a different file right before deserializing, and the files look structurally identical to me.
>
>The serialized file:
>
>  <?xml version="1.0" ?>
>- <ArrayOfTicketPurchaseItem xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>- <TicketPurchaseItem>
>- <EventItem>
>  <Key>7</Key>
>  <Value>High Holy Days (all services)</Value>
>  </EventItem>
>- <SectionItem>
>  <Key>1</Key>
>  <Value>VIP</Value>
>  </SectionItem>
>  <AdultAmount>250</AdultAmount>
>  <ChildAmount>0</ChildAmount>
>  <AdultQuantity>2</AdultQuantity>
>  <ChildQuantity>1</ChildQuantity>
>  </TicketPurchaseItem>
>  </ArrayOfTicketPurchaseItem>
>
>And the file that I saved when trying to deserialize:
>
>  <?xml version="1.0" ?>
>- <ArrayOfTicketPurchaseItem xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>- <TicketPurchaseItem>
>- <EventItem>
>  <Key>3</Key>
>  <Value>Rosh Hashanah</Value>
>  </EventItem>
>- <SectionItem>
>  <Key>2</Key>
>  <Value>Reserved</Value>
>  </SectionItem>
>  <AdultAmount>75</AdultAmount>
>  <ChildAmount>0</ChildAmount>
>  <AdultQuantity>5</AdultQuantity>
>  <ChildQuantity>2</ChildQuantity>
>  </TicketPurchaseItem>
>- <TicketPurchaseItem>
>- <EventItem>
>  <Key>7</Key>
>  <Value>High Holy Days (all services)</Value>
>  </EventItem>
>- <SectionItem>
>  <Key>2</Key>
>  <Value>Reserved</Value>
>  </SectionItem>
>  <AdultAmount>175</AdultAmount>
>  <ChildAmount>0</ChildAmount>
>  <AdultQuantity>2</AdultQuantity>
>  <ChildQuantity>2</ChildQuantity>
>  </TicketPurchaseItem>
>- <TicketPurchaseItem>
>- <EventItem>
>  <Key>3</Key>
>  <Value>Rosh Hashanah</Value>
>  </EventItem>
>- <SectionItem>
>  <Key>0</Key>
>  <Value>Inner Circle</Value>
>  </SectionItem>
>  <AdultAmount>500</AdultAmount>
>  <ChildAmount>0</ChildAmount>
>  <AdultQuantity>1</AdultQuantity>
>  <ChildQuantity>2</ChildQuantity>
>  </TicketPurchaseItem>
>- <TicketPurchaseItem>
>- <EventItem>
>  <Key>7</Key>
>  <Value>High Holy Days (all services)</Value>
>  </EventItem>
>- <SectionItem>
>  <Key>0</Key>
>  <Value>Inner Circle</Value>
>  </SectionItem>
>  <AdultAmount>500</AdultAmount>
>  <ChildAmount>0</ChildAmount>
>  <AdultQuantity>5</AdultQuantity>
>  <ChildQuantity>2</ChildQuantity>
>  </TicketPurchaseItem>
>  </ArrayOfTicketPurchaseItem>
>
>
>Sorry about the lame IE formatting, but the source of the deserialization data is a Text field in a table that does not have any formatting at all.
>
>Has anyone had this missing root element problem already and can give me some pointers on how to avoid it?
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform