Results 1 to 2 of 2

Thread: A little help

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Santo Domingo,D.N., Dom. Rep.
    Posts
    707

    Talking A little help

    I am newbie in VB.NET. I just trying to create a xml file and then read back.
    What is wrong in this code?
    The File is not created
    Imports System.Xml.Serialization.XmlSerializer
    Imports System.IO
    Imports System.Console
    Module Module1

    Sub Main()

    End Sub
    Sub testingXml()
    Dim Ser As New Xml.Serialization.XmlSerializer(GetType(Customer))
    Dim Cust As New Customer(1, "Luis Moises", "EL CARIBE", "Santo Domingo")
    Dim Fs As New FileStream("c:\lmr\customer.xml", FileMode.Create)
    Ser.Serialize(Fs, Cust)
    Fs.Close()

    Dim Fs2 As New FileStream("c:\lmr\customer.xml", FileMode.Open)
    Dim Cust2 As New Customer
    Cust2 = CType(Ser.Deserialize(Fs2), Customer)
    Fs2.Close()
    End Sub

    Public Class Customer
    Dim ID As Integer
    Dim Nombre As String
    Dim Direccion As String
    Dim Ciudad As String
    Sub New()

    End Sub
    Sub New(ByVal id As Integer, ByVal nombre As String, ByVal direccion As String, ByVal ciudad As String)
    Me.ID = id
    Me.Nombre = nombre
    Me.Direccion = direccion
    Me.Ciudad = ciudad
    End Sub
    End Class

    End Module

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you need to declare the Class " Dim Cust As New Customer " before declaring the XmlSerializer at a guess , because your trying to get an empty type with the part that says ... (GetType(Customer))
    , eg:
    VB Code:
    1. Dim Cust As New Customer(1, "Luis Moises", "EL CARIBE", "Santo Domingo")
    2.  
    3. Dim Ser As New Xml.Serialization.XmlSerializer(GetType(Cust))
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width