whizkid123 Posted December 13, 2002 Posted December 13, 2002 When I try to read an XML file from my Vb.net project, it gives an error saying "AN UNHANDLED EXCEPTION OF TYPE SYSTEM.INVALIDOPERATIONEXCEPTION OCCURRED IN SYSTEM.XML.DLL. ADDITIONAL INFO: THERE IS AN ERROR IN XML DOCUMENT (2,2)." on the deserialize line. There is no problem with the XML file. I'm able to read the same file thro another application. I've tried everything but it still persists. The project where it is giving an error is migrated from VB6.0, if that matters. Please help! Quote
Moderators Robby Posted December 13, 2002 Moderators Posted December 13, 2002 Can you post some of the code? :) Quote Visit...Bassic Software
whizkid123 Posted December 13, 2002 Author Posted December 13, 2002 (edited) Public Shared Function Load(ByVal filename As String, ByVal newType As Type) As Object Dim fileinfo As New FileInfo(filename) If fileinfo.Exists = False Then Return System.Activator.CreateInstance(newtype) End If Dim stream As New FileStream(filename, FileMode.Open) Dim newobj As Object = Load(stream, newType) stream.Close() Return newobj End Function Public Shared Function Load(ByVal stream As Stream, ByVal newtype As Type) As Object Dim Serializer As New XmlSerializer(newtype) Dim newobj As Object = Serializer.Deserialize(stream) Return newobj End Function 'The above are the two serializing functions. The error is coming 'in the second function when it's tring to deserialize. I'm getting 'the file name from a data file name property Public ReadOnly Property DataFilename() As String Get Dim folder As String folder = Environment.CurrentDirectory Return folder & "\surveyor.xml" End Get End Property [edit]added [ vb ] tags [/ vb ] [/edit] Edited December 13, 2002 by Derek Stone Quote
*Gurus* Derek Stone Posted December 13, 2002 *Gurus* Posted December 13, 2002 You really should be declaring newobj as the exact type the XML file will be deserialized into. As it stands currently, you're trying to read it into an Object. Also keep in mind that not everything serializes to XML correctly. Certain classes and objects just won't be formatted correctly. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.