Deserialization problem

P

Peter

Hi,

I have created several classes,one act as a base class,all the others
inherits from it. The base class contains many complex datas(some
properties,arrays and structures). Now I want to serialize an instance of
the inherited class . I made a binary serialization and no error occurs. But
when I deserialized the result file of the binary serialization ,it gave me
an error message: System MissingMemberException: FieldInfo can't match the
destination data type.

Need I implements the System.Runtime.Serialization.ISerializable and fill
the subroutine below?

Public Sub GetObjectData(ByVal info As _
System.Runtime.Serialization.SerializationInfo, _
ByVal context As System.Runtime.Serialization.StreamingContext)

if so, I will need to add many line such as info.AddValue("X", varible).

Any help would be greatly appreciated.

Thanks
 
P

Peter

Sorry, Ken, I was offline for two days. My program is like below

Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.binary

<Serializable()> Public Class zCMethod
Public Name As String
Protected mSubType As Short

Sub New(ByVal sMethodName As String)

End Sub

End Class


<Serializable()> Public Class zCGeneralMetalTensile
Inherits CMethod

Sub New(ByVal sName As String, ByVal iSubType As Short)
MyBase.new(sName)
msubtype = iSubType

End Sub

Public Overrides Sub SerializeMethod()
If File.Exists("MyMethod.bin") Then File.Delete("MyMethod.bin")

Dim Formatter As New BinaryFormatter
Dim Stream As New FileStream("MyMethod.bin", FileMode.Create, _
FileAccess.Write, FileShare.None)
Formatter.Serialize(Stream, Me)
Stream.Close()

End Sub

Public Sub DeserializeMethod()
Try
If System.IO.File.Exists("MyMethod.bin") Then
Dim Formatter As New BinaryFormatter
Dim streamRead As New FileStream("MyMethod.bin",
FileMode.Open, _
FileAccess.Read,
FileShare.Read)

Formatter.Deserialize(streamRead)
streamRead.Close()

End If

Catch e As System.MissingMemberException
MsgBox(e.ToString)


End Try

End Sub

End Class


When I declared and called the class's method "zMethod.DeserializeMethod"
like below, I got an error message:
system: MissingMemberException: FieldInfo can't match the destination type.

Dim zMethod As zCGeneralMetalTensile = New
zCGeneralMetalTensile("q2", 0)

zMethod.SerializeMethod()

zMethod.DeserializeMethod()

Thanks in advance

Peter
 
P

Peter

Sorry, I provided the wrong codes in the last mail. My codes should be like
this:

Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.binary

Imports System.Data.OleDb

<Serializable()> Public Class zCMethod
public Name as string
Public Specimen As Specimens

Protected mSubType As Short


Sub New(ByVal sMethodName As String)

Specimen.Initialize()

End Sub

<Serializable()> Structure Specimens
Dim Geometry() As Single

Public Sub Initialize()
ReDim Geometry(9)
End Sub

End Structure

End Class


<Serializable()> Public Class zCGeneralMetalTensile
Inherits zCMethod

Sub New(ByVal sName As String, ByVal iSubType As Short)
MyBase.new(sName)
msubtype = iSubType

End Sub

Public Sub SerializeMethod()
If File.Exists("MyMethod.bin") Then File.Delete("MyMethod.bin")

Dim Formatter As New BinaryFormatter
Dim Stream As New FileStream("MyMethod.bin", FileMode.Create, _
FileAccess.Write, FileShare.None)
Formatter.Serialize(Stream, Me)
Stream.Close()

End Sub

Public Sub DeserializeMethod()
Try
If System.IO.File.Exists("MyMethod.bin") Then
Dim Formatter As New BinaryFormatter
Dim streamRead As New FileStream("MyMethod.bin",
FileMode.Open, _
FileAccess.Read,
FileShare.Read)

Formatter.Deserialize(streamRead)
streamRead.Close()

End If

Catch e As System.MissingMemberException
MsgBox(e.ToString)


End Try

End Sub

End Class


When I declared and called "zMethod.DeserializeMethod"
like below, I got an error message:
system: MissingMemberException: FieldInfo can't match the destination
type.
I found the error appears only because I called "Specimen.Initialize" . If I
delete the "Specimen.Initialize" no error appears.

Dim zMethod As zCGeneralMetalTensile = New
zCGeneralMetalTensile("q2", 0)

zMethod.SerializeMethod()

zMethod.DeserializeMethod()

Thanks in advance

Peter
 

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