K
kevininstructor
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 then my current one? 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
(e-mail address removed)
..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
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 then my current one? 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
(e-mail address removed)
..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