Serialize and deserialize

A

Amsteel

I got something like this in VB.Net

<Serializable()> Public Class YQProfileC
Inherits CollectionBase
Public Sub Save2File(ByVal FileName As String)
Dim IFormatter As New BinaryFormatter()
Dim FS As FileStream = New FileStream(FileName, FileMode.Create,
FileAccess.Write, FileShare.None)
IFormatter.Serialize(FS, Me)
FS.Close()
End Sub

Public Function LoadFromFile(ByVal FileName As String) As YQProfileC
Dim IFormatter As New BinaryFormatter()
Dim FS As FileStream = New FileStream(FileName, FileMode.Open,
FileAccess.Read, FileShare.None)
Return IFormatter.Deserialize(FS)
End Function
End Class

Now I got two problem here:
1.For some reason, the Root space name of the project needs to be changed
from YQV020 to YQV. But after that, how could I deserialize the old file.
2.What would have been done to deserialize the file if we want o change the
code from VB.net to C#.net? Please don't ask me why.

Thanks very much.


Amsteel
 
J

Jay B. Harlow [MVP - Outlook]

Amsteel,
1.For some reason, the Root space name of the project needs to be changed
from YQV020 to YQV. But after that, how could I deserialize the old file.
The following three part article covers binary serialization in detail:
http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

I believe the third one discusses what to do if the namespace changes.
2.What would have been done to deserialize the file if we want o change the
code from VB.net to C#.net? Please don't ask me why.
Changing from VB.NET to C# should not effect anything, as long as both types
are "exactly" the same. For the change in the 'name' (version number really)
you can use the code in the above articles.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top