XML Serialization

asp.net India
  • 17 years ago

    I am working on XML Serialization/deserialization.I have a class called clsPerson.vb (Given below)  that i am trying to serialize / deserialize


    Imports System.Xml.Serialization
    Imports System.IO
    Imports System
    Imports System.Data
    Imports System.Drawing
    Imports System.Web
    Imports System.Xml



    <XmlRoot(ElementName:="Class_Person")> _
    Public Class clsPerson
       Private strName As String
       Private intAge As Integer


       <XmlElement(ElementName:="Property_Name")> _
       Public Property Name() As String
           Get
               Return strName
           End Get
           Set(ByVal strValue As String)
               strName = strValue
           End Set
       End Property


       <XmlElement(ElementName:="Property_Age")> _
       Public Property age() As Integer
           Get
               Return intAge
           End Get
           Set(ByVal intValue As Integer)
               intAge = intValue
           End Set
       End Property
       Public Function Hello() As String
           Dim s As String
           s = "Hi! My name is " & Name & " and I am " & Age & " years old."
           Return s
       End Function
       Public Function Goodbye() As String
           Return "So long!"
       End Function


    End Class


    I am trying to serialize the  class using the following code


           Dim oXS As XmlSerializer   = New XmlSerializer(GetType(clsPerson))
            Dim objPerson As New clsPerson()
           objPerson.Name = "Sabarish"
           objPerson.age = 26
           Response.Write(objPerson.Hello() & "<br>")
           Response.Write(objPerson.Goodbye() & "<br>")
           'Serialize object to XML and write it to XML file
           Dim objStmw As StreamWriter
           objStmw = New StreamWriter(Server.MapPath("lucky.xml"))
           oXS.Serialize(objStmw, objPerson)
           objStmw.Close()


    When i run the code i get the following error


    File or assembly name sc5_x2xc.dll, or one of its dependencies, was not found.
    Line 53:  Dim oXS As XmlSerializer   = New XmlSerializer(GetType(clsPerson))


    and the funniest part is that the dll name sc5_x2xc.dll keeps on changing, can any one help me on this







Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout