473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Deserialization problem

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
Nov 21 '05 #1
3 989
Hi,

Need to see more of your code to help. Here is a link on how to
make a class serializable.

http://msdn.microsoft.com/library/de...classtopic.asp

Ken
----------------------------------

"Peter" wrote:
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

Nov 21 '05 #2
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
Nov 21 '05 #3
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

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TEK | last post by:
There seems to be a bug when deserialization some classes in the .NET framework. If you try to deserialize a class that has a base class that holds a struct with a member that is implementing...
2
by: Meta-Meta | last post by:
Hi, I'm trying to deserialize a VC++ .NET class and am stumped by the following problem : In order to create the XmlSerializer you need to pass the type of the object being created. The doc...
2
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on...
3
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database...
3
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
1
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client...
5
by: Greg Allen | last post by:
I am consuming a web service and using the generated Reference.cs to access the service and the objects associated with it. I have run into a problem where some inherited classes are not being...
3
by: John Glover | last post by:
To whoever can help, I've been having a problem with XML deserialization lately. I needed to serialize and deserialze two objects which inherited from Hashtable. Because IDictionary...
7
by: Andrew | last post by:
Hi, I am using DataContractJsonSerializer to deserialize JSON string in C# objects but I am having a problem. Suppose I have a class: class Item { public ItemId Id { get; set; }
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.