Serialization problem between 2 apps

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc

    #1

    Serialization problem between 2 apps

    Hi,
    I am trying to serialize a data structure -- a list (of custom class)
    -- in one application, then read it in with another application. My
    serialize and deserialize subs are in a module that is shared between
    the two applications, so they are using exactly the same code (this
    module also contains the class, so I am certain the class code is the
    same)

    The code I'm using is quite simple, so I'm not sure where I'm going
    wrong:

    Private AllOrders as List (Of CustomOrder)

    Function SerializeOrders (ByVal Path As String) As Integer
    'Writes (serializes) All Orders to disk at given path
    Dim myFileStream As New System.IO.FileS tream(Path,
    System.IO.FileM ode.Create)
    Dim MyFormatter As New
    System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er()

    If (AllOrders IsNot Nothing) Then
    MyFormatter.Ser ialize(myFileSt ream, AllOrders)
    End If
    myFileStream.Cl ose()
    End Function

    Function DeserializeOrde rs(ByVal path As String) As Integer
    ' Reads list of orders from given path and OVERWRITES AllOrders
    Dim myFileStream As New System.IO.FileS tream(path,
    System.IO.FileM ode.OpenOrCreat e)
    Dim MyFormatter As New
    System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er()

    Dim GenericObject As Object
    Try
    GenericObject = MyFormatter.Des erialize(myFile Stream)
    AllOrders = CType(GenericOb ject, List(Of TEOrder))
    Catch ex As Exception
    Finally
    myFileStream.Cl ose()
    End Try
    End Function

    No exception is ever raised. When I serialize, I can check the file
    and it contains data (which means that serialization is working).
    However, when I deserialize in the other application, I get 0 objects.

    A final observation: serialization & deserialization work fine when
    done within the same application. It is only between applications
    that I have the problem.

    Help?

    BTW I would be interested in using the SOAPFormatter but I can't find
    it in VB.NET. I read about it online but don't see it available.
    What do I need to do to make that available to me? (I would much
    prefer human-readable output when I serialize)

    Thanks,
    Marc

  • schneider

    #2
    Re: Serialization problem between 2 apps

    Try posting the exception instead of catching and hiding them.

    Schneider

    "Marc" <newmexicoguaca mole@gmail.comw rote in message
    news:1176732892 .962833.133040@ p77g2000hsh.goo glegroups.com.. .
    Hi,
    I am trying to serialize a data structure -- a list (of custom class)
    -- in one application, then read it in with another application. My
    serialize and deserialize subs are in a module that is shared between
    the two applications, so they are using exactly the same code (this
    module also contains the class, so I am certain the class code is the
    same)
    >
    The code I'm using is quite simple, so I'm not sure where I'm going
    wrong:
    >
    Private AllOrders as List (Of CustomOrder)
    >
    Function SerializeOrders (ByVal Path As String) As Integer
    'Writes (serializes) All Orders to disk at given path
    Dim myFileStream As New System.IO.FileS tream(Path,
    System.IO.FileM ode.Create)
    Dim MyFormatter As New
    System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er()
    >
    If (AllOrders IsNot Nothing) Then
    MyFormatter.Ser ialize(myFileSt ream, AllOrders)
    End If
    myFileStream.Cl ose()
    End Function
    >
    Function DeserializeOrde rs(ByVal path As String) As Integer
    ' Reads list of orders from given path and OVERWRITES AllOrders
    Dim myFileStream As New System.IO.FileS tream(path,
    System.IO.FileM ode.OpenOrCreat e)
    Dim MyFormatter As New
    System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er()
    >
    Dim GenericObject As Object
    Try
    GenericObject = MyFormatter.Des erialize(myFile Stream)
    AllOrders = CType(GenericOb ject, List(Of TEOrder))
    Catch ex As Exception
    Finally
    myFileStream.Cl ose()
    End Try
    End Function
    >
    No exception is ever raised. When I serialize, I can check the file
    and it contains data (which means that serialization is working).
    However, when I deserialize in the other application, I get 0 objects.
    >
    A final observation: serialization & deserialization work fine when
    done within the same application. It is only between applications
    that I have the problem.
    >
    Help?
    >
    BTW I would be interested in using the SOAPFormatter but I can't find
    it in VB.NET. I read about it online but don't see it available.
    What do I need to do to make that available to me? (I would much
    prefer human-readable output when I serialize)
    >
    Thanks,
    Marc
    >

    Comment

    • Chris Dunaway

      #3
      Re: Serialization problem between 2 apps

      On Apr 16, 9:14 am, "Marc" <newmexicoguaca m...@gmail.comw rote:
      Hi,
      I am trying to serialize a data structure -- a list (of custom class)
      -- in one application, then read it in with another application. My
      serialize and deserialize subs are in a module that is shared between
      the two applications, so they are using exactly the same code (this
      module also contains the class, so I am certain the class code is the
      same)
      What does this mean, exactly? Have you placed your serialization code
      in a class library and both applications reference that library? Or do
      both applications simply share the same code file? If they share the
      same code file, then that is likely your problem. Even if they have
      identical code, the classes are still considered different types and
      the second application will not be able to deserialize the file that
      is serialized by the first.

      <snip>
      Try
      GenericObject = MyFormatter.Des erialize(myFile Stream)
      AllOrders = CType(GenericOb ject, List(Of TEOrder))
      Catch ex As Exception
      Finally
      myFileStream.Cl ose()
      End Try
      End Function
      >
      No exception is ever raised. When I serialize, I can check the file
      As the other poster pointed out, you are catching and swallowing the
      exception.
      >
      BTW I would be interested in using the SOAPFormatter but I can't find
      it in VB.NET. I read about it online but don't see it available.
      What do I need to do to make that available to me? (I would much
      prefer human-readable output when I serialize)
      The SoapFormatter is defined in the
      System.Runtime. Serialization.F ormatters.Soap namespace which is
      contained, coincidentally, in
      System.Runtime. Serialization.F ormatters.Soap. dll. Add a reference to
      that assembly and you can get at the SoapFormatter.

      Chris

      Comment

      • Marc

        #4
        Re: Serialization problem between 2 apps

        On Apr 17, 8:36 am, Chris Dunaway <dunaw...@gmail .comwrote:
        On Apr 16, 9:14 am, "Marc" <newmexicoguaca m...@gmail.comw rote:
        >
        Hi,
        I am trying to serialize a data structure -- a list (of custom class)
        -- in one application, then read it in with another application. My
        serialize and deserialize subs are in a module that is shared between
        the two applications, so they are using exactly the same code (this
        module also contains the class, so I am certain the class code is the
        same)
        >
        What does this mean, exactly? Have you placed your serialization code
        in a class library and both applications reference that library? Or do
        both applications simply share the same code file? If they share the
        same code file, then that is likely your problem. Even if they have
        identical code, the classes are still considered different types and
        the second application will not be able to deserialize the file that
        is serialized by the first.
        >
        <snip>
        >
        Try
        GenericObject = MyFormatter.Des erialize(myFile Stream)
        AllOrders = CType(GenericOb ject, List(Of TEOrder))
        Catch ex As Exception
        Finally
        myFileStream.Cl ose()
        End Try
        End Function
        >
        No exception is ever raised. When I serialize, I can check the file
        >
        As the other poster pointed out, you are catching and swallowing the
        exception.
        >
        >
        >
        BTW I would be interested in using the SOAPFormatter but I can't find
        it in VB.NET. I read about it online but don't see it available.
        What do I need to do to make that available to me? (I would much
        prefer human-readable output when I serialize)
        >
        The SoapFormatter is defined in the
        System.Runtime. Serialization.F ormatters.Soap namespace which is
        contained, coincidentally, in
        System.Runtime. Serialization.F ormatters.Soap. dll. Add a reference to
        that assembly and you can get at the SoapFormatter.
        >
        Chris
        Thanks Chris (and Schneider)

        I decided to investigate the exceptions a little more and realized
        that because I was simply using two copies of the same class files,
        the namespaces were not shared and I could not share objects. Thus I
        have created a class library which is used by both applications now,
        and I am gleefully sharing objects.

        (Then I checked the newgroup and found Chris's reply, which would have
        saved me a lot of time if it had come a few hours earlier!)

        Also thanks for the SoapFormatter information.

        Regards,
        Marc

        Comment

        Working...