469,270 Members | 1,733 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Serializable class problem

I created two classes called "site" and "Sites" which use 'BinaryFormatter'
to load and save class information to a disk file. In my test application
all works fine but when implementing into another application the code fails
with a message indicating there is a missing assembly. The missing assembly
is the project which serialized the class information to disk e.g.

Test1a, created binary files
DDEP attempted to read them but error points to "Test1a"
My solution was to recreate the data file in the DDEP project which then
marks the data for DDEP and "Test1a" gets the exception "can not find
assembly..."
MY QUESTION:
With the supplied code in mind is there a work around which would allow the
binary disk file to be accessed by any .NET application, or do I need a
different solution to mine? Please note I would like to stay binary to keep
the average user out of the files content.

Thanks for taking the time to read this message and provide feedback,
Kevin

..NET version 1.1, 2003

Code sniplet
----------------------------------------------------------------
Imports System
Imports System.Configuration
Imports System.IO
Imports System.Data
Imports Dart.PowerTCP
Imports System.Runtime.Serialization.Formatters.Binary
Imports DOR.Utils.Encryption
Imports System.ComponentModel

<Serializable()> Public Class Site
....
End Class

Public Class Sites
Inherits CollectionBase
....
Public Function LoadSitesFromDataFile() As Boolean
Dim BinF As New BinaryFormatter
Dim obj As Object
Dim oSite As Site

If System.IO.File.Exists(DataFile) Then
Try
Dim FS As New System.IO.FileStream(DataFile,
IO.FileMode.OpenOrCreate)
Dim ds As Encryption64 = New Encryption64
Do
obj = BinF.Deserialize(FS)
If obj.GetType Is GetType(Site) Then
oSite = CType(obj, Site)
If oSite.Password.Length > 0 Then
oSite.Password =
ds.DecryptFromBase64String(oSite.Password, Me.UnLockString)
End If
Me.Add(oSite)
End If
Loop While FS.Position < FS.Length - 1
FS.Close()
ds = Nothing
Return True
Catch ioe As System.IO.IOException
Me.m_LastError = TheCaller & Environment.NewLine & ioe.Message
Return False
Catch ex As Exception
Me.m_LastError = TheCaller & Environment.NewLine & ex.Message
Return False
End Try
Else
Return False
End If
End Function
Public Function SaveSitesToDataFile() As Boolean
Const TheCaller As String = "Sites.SaveSitesToDataFile"
If Me.Count = 0 Then
' TODO
Return False
End If
Dim BinF As New BinaryFormatter
Try
Dim FS As New System.IO.FileStream(DataFile, IO.FileMode.Create)
Dim ds As Encryption64 = New Encryption64
Dim oSite As Site

For Each oSite In Me
If oSite.Password.Length > 0 Then
oSite.Password = ds.EncryptToBase64String(oSite.Password,
UnLockString)
End If
BinF.Serialize(FS, oSite)
Next
FS.Close()
ds = Nothing
Catch ioe As System.IO.IOException
' TODO
Return False
Catch ex As Exception
Return False
End Try
End Function
End Class
Nov 21 '05 #1
1 1083
Since there are no replies I am moving this message to "DotNet General"
Forumn. If a moderator can remove this message here that would be great.
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by xmail123 | last post: by
3 posts views Thread by Barguast | last post: by
2 posts views Thread by John | last post: by
2 posts views Thread by Frank Uray | last post: by
1 post views Thread by MrFile | last post: by
3 posts views Thread by Techno_Dex | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.