473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XML Deserialzing causes exception

Hello,

I'm trying to deserialize a document created with the following pieces of
code.

I get an exception "Additional information: There is an error in XML
document (2, 2).", why does this happen?

Serializing code:

Dim fs As New FileStream(Filename, FileMode.Create, FileAccess.Write)
Dim SoundTableItem As SoundTableItem = Nothing
For Each SoundTableItem In SoundItems

Dim XmlEntry As New
Xml.Serialization.XmlSerializer(GetType(SoundTable Item))
XmlEntry.Serialize(fs, SoundTableItem)

Next

fs.Close()

Deserializing code:

Dim fs As New FileStream(Filename, FileMode.Open, FileAccess.Read)
Dim tr As New Xml.XmlTextReader(fs)
Dim XmlEntry As New Xml.Serialization.XmlSerializer(GetType(SoundTable Item))
While Not tr.EOF()
Dim SoundEntry As SoundTableItem = Nothing
SoundEntry = XmlEntry.Deserialize(tr)
SoundItems.Add(SoundEntry)
End While

--
Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
Nov 20 '05 #1
4 958
Hi Simon.

I made an other serialize routine using the stringwriter, you can try it.
It is changed the code in this message so there can be typos.

Dim Serializer As New
Xml.Serialization.XmlSerializer(GetType(BelgenColl ection))
Dim sw As New System.IO.StringWriter
Serializer.Serialize(sw, Belgen)
dim mystring = sw.ToString

Dim Deserializer As New Xml.Serialization.XmlSerializer _
(GetType(BelgenCollection))
Dim sr As New System.IO.StringReader(Charles)
Dim reader As New System.Xml.XmlTextReader(sr)
Dim Vlamingen As BelgenCollection
Vlamingen = CType(Deserializer.Deserialize(reader), _
BelgenCollection)

It has to be a proper object.

Cor
Nov 20 '05 #2
Hi Simon,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to serialized an array
of objects into xml.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

In addition to to Cor's suggestion, I think you may try to take a look at
the link below.

How to xml serialize arraylist of objects?
http://groups.google.com/groups?hl=z...&selm=bC07akcA
EHA.612%40cpmsftngxa06.phx.gbl&rnum=3

If you still have any concern on this issue, please feel free to let me
know.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #3
Thanks for your link, your code examples came in handy and I have managed to
get it to work :-)

Are there any books that you would recommend that help in this area?

Best Wishes
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:tL**************@cpmsftngxa10.phx.gbl...
Hi Simon,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to serialized an array
of objects into xml.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

In addition to to Cor's suggestion, I think you may try to take a look at
the link below.

How to xml serialize arraylist of objects?
http://groups.google.com/groups?hl=z...&selm=bC07akcA
EHA.612%40cpmsftngxa06.phx.gbl&rnum=3

If you still have any concern on this issue, please feel free to let me
know.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 20 '05 #4
Hi Simon,

Thank you for your update.
I think the book below will be a good start about XML Programming.
Applied XML Programming for Microsoft .NET
http://www.microsoft.com/mspress/books/6235.asp
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kari Hallfast | last post by:
Hi, I'm a C++ programmer and I have just recently decided to use Python as an embedded scripting language. I call Py_Initialize(), run a few scripts and call PyFinalize() which causes an unhandled...
8
by: SunshineGirl | last post by:
I'm trying to trigger an app with the following code from a message queue. It works with only the message box voilą! enabled. But it causes the exception below when it is triggered with the rest of...
0
by: Pegaso | last post by:
Hi... I have created a utility library with VC++ 7.1 which is used by a VB 6 client. The library creates a secondary thread of execution in order to listen for connections on a socket. The...
0
by: **Developer** | last post by:
This is almost the same as a previous post that is still giving me a problem, but with a different slant. I can't seem to find out what is wrong. My program crashes after it leaves an event...
2
by: google | last post by:
I statically link the Synopsys Milkyway C-API library ("MDA") into my C++ application. When my C++ application throws an exception, it seg faults instead. The details of my environment are:...
3
by: doubts | last post by:
Hi all, I am trying to convert my bulk of code from VC++ 6.0 to VC++.Net. when using std::string type variable, the application causes exception at one instance and does not cause an exception at...
0
by: Griff | last post by:
Overview When the first call to our Web Service causes an exception, the Web Service caches that user's credentials for its life time. Details We have a Web Service which uses Windows...
3
by: =?Utf-8?B?TWF0dA==?= | last post by:
I am using the PetShop example's ExecuteReader function: public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter...
3
by: Ken Shimizu | last post by:
I get an error when submitting an .ASPX page in Safari beta, MAC and PC document.getElementbyId(‘FolderBrowser’).submit(); After the server side code has executed without problems I get the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.