PC Review


Reply
Thread Tools Rate Thread

Serialization problem between 2 apps

 
 
Marc
Guest
Posts: n/a
 
      16th Apr 2007
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.FileStream(Path,
System.IO.FileMode.Create)
Dim MyFormatter As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()

If (AllOrders IsNot Nothing) Then
MyFormatter.Serialize(myFileStream, AllOrders)
End If
myFileStream.Close()
End Function

Function DeserializeOrders(ByVal path As String) As Integer
' Reads list of orders from given path and OVERWRITES AllOrders
Dim myFileStream As New System.IO.FileStream(path,
System.IO.FileMode.OpenOrCreate)
Dim MyFormatter As New
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()

Dim GenericObject As Object
Try
GenericObject = MyFormatter.Deserialize(myFileStream)
AllOrders = CType(GenericObject, List(Of TEOrder))
Catch ex As Exception
Finally
myFileStream.Close()
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

 
Reply With Quote
 
 
 
 
schneider
Guest
Posts: n/a
 
      16th Apr 2007
Try posting the exception instead of catching and hiding them.

Schneider

"Marc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.FileStream(Path,
> System.IO.FileMode.Create)
> Dim MyFormatter As New
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
>
> If (AllOrders IsNot Nothing) Then
> MyFormatter.Serialize(myFileStream, AllOrders)
> End If
> myFileStream.Close()
> End Function
>
> Function DeserializeOrders(ByVal path As String) As Integer
> ' Reads list of orders from given path and OVERWRITES AllOrders
> Dim myFileStream As New System.IO.FileStream(path,
> System.IO.FileMode.OpenOrCreate)
> Dim MyFormatter As New
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
>
> Dim GenericObject As Object
> Try
> GenericObject = MyFormatter.Deserialize(myFileStream)
> AllOrders = CType(GenericObject, List(Of TEOrder))
> Catch ex As Exception
> Finally
> myFileStream.Close()
> 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
>



 
Reply With Quote
 
Chris Dunaway
Guest
Posts: n/a
 
      17th Apr 2007
On Apr 16, 9:14 am, "Marc" <newmexicoguacam...@gmail.com> wrote:
> 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.Deserialize(myFileStream)
> AllOrders = CType(GenericObject, List(Of TEOrder))
> Catch ex As Exception
> Finally
> myFileStream.Close()
> 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.Formatters.Soap namespace which is
contained, coincidentally, in
System.Runtime.Serialization.Formatters.Soap.dll. Add a reference to
that assembly and you can get at the SoapFormatter.

Chris

 
Reply With Quote
 
Marc
Guest
Posts: n/a
 
      17th Apr 2007
On Apr 17, 8:36 am, Chris Dunaway <dunaw...@gmail.com> wrote:
> On Apr 16, 9:14 am, "Marc" <newmexicoguacam...@gmail.com> wrote:
>
> > 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.Deserialize(myFileStream)
> > AllOrders = CType(GenericObject, List(Of TEOrder))
> > Catch ex As Exception
> > Finally
> > myFileStream.Close()
> > 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.Formatters.Soap namespace which is
> contained, coincidentally, in
> System.Runtime.Serialization.Formatters.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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive XML serialization? XML serialization of cyclic objects? =?ISO-8859-1?Q?=22Andr=E9s_G=2E_Aragoneses_=5B_kno Microsoft C# .NET 2 16th Jan 2007 04:52 PM
Apps that start other apps a problem Pierre Carlson Windows XP Help 2 4th Aug 2006 09:42 PM
Serialization and de-serialization of types loaded from assembly at runtime mookid8000@gmail.com Microsoft C# .NET 6 1st Mar 2006 10:27 AM
A serialization problem Mike Microsoft C# .NET 2 17th Jun 2004 04:44 PM
winsock problem? some apps can't access any web site, most apps have no problems. W2K SP4+ Clark Wilson Microsoft Windows 2000 Networking 1 14th Sep 2003 03:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:31 PM.