473,513 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serializing complex object

Consider the following simple class:

<Serializable()> _
Public Class SimpleClass
Private m_AString As String
Private m_AByteArray As Byte()

Public Property AString() As String
. . .
End Property

Public Property AByteArray() As Byte()
. . .
End Property
End Class

I can use xml serialization to serialize an instance of this class to a
file. Works fine. Now I want to make it a little more complex like the
following two classes:

<Serializable()> _
Public Class DataFile
Private m_FileName As String
Private m_FileData As Byte()

Public Property FileName() As String
. . .
End Property

Public Property FileData() As Byte()
. . .
End Property
End Class

<Serializable()> _
Public Class ComplexClass
Private m_AString As String
'An array of DataFile objects
Private m_aDataFiles As DataFile()

Public Property AString() As String
. . .
End Property

Public Property DataFiles() As DataFile()
. . .
End Property
End Class

When I try to serialize an instance of the ComplexClass, I get an
exception:

"There was an exception reflecting type 'Complex Class'

Here is the code I use to serialize the object. The exception occurs on
the line indicated:

Private Sub Button1_Click(...) Handles Button1.Click
Dim oTest As New ComplexClass

oTest.AString = "One"
ReDim oTest.DataFiles(1)

oTest.DataFiles(0) = New DataFile("c:\test\testme.en.wav")
oTest.DataFiles(1) = New DataFile("c:\test\my recording.en.wav")

Dim fs As New FileStream("c:\Complex.xml", FileMode.Create)
'**** ERROR OCCURS ON FOLLOWING LINE ****
Dim xs As New XmlSerializer(GetType(ComplexClass))

xs.Serialize(fs, oTest)
End Sub
Is it possible to do what I want?

Thanks,

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #1
1 1164
On Thu, 18 Nov 2004 14:47:10 -0600, Chris Dunaway wrote:

Is it possible to do what I want?


Wouldn't you know it? Shortly after I submitted this question, I found the
answer. By digging into the stack trace, it turns out that the classes
involved must have a default parameterless constructor, which I did not
have in my test. Once I added that, it worked like a charm.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #2

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

Similar topics

2
332
by: Martin. D. Waller | last post by:
Hello, Does anyone kow of any good examples or documents that talk about serializing complex objects and object graphs to XML. Basically I would like to have a class that references other...
1
2067
by: Ivo Bronsveld | last post by:
All, I have quite a challenging task ahead of me. I need to write an object model (for code access) based on a schema, which cannot be made into a dataset because of it's complexity. So I...
2
3501
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: +...
8
1388
by: Joe | last post by:
Hello All: Say I have a solution with two projects (Project1 and Project2) and each project contains a class (Project1 contains Class1 and Project2 contains Class2). The projects don't...
2
1590
by: Dennis | last post by:
Does anyone know why this code gives an error: <serializeable> public structure TestSerialize anumber as integer astring as string end strucuture Dim t As TestSerialize Dim formatter As New...
2
5451
by: JEB | last post by:
I have an object that wrote the serialization for to use with Remoting and now I would like to use it with Web Services. The object consist of a short and a string value (lets call it Item). This...
2
331
by: Charles Law | last post by:
I have a complex object that I am serializing, and I would like to omit elements that have a default value. For example, if I have a class as follows Public Class Test Private m_Name As...
47
3078
by: Max | last post by:
Due to the behaviour of a particular COM object, I need to ensure that a request for a particular ASP page is finalized before another request for the page is processed. Does IIS have a way to...
5
4208
by: | last post by:
I've got a basic "chat" infrastructure that can send objects across the wire, but I'm running into a few issues with trying to send multiple messages and things behaving differently in debug and...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
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...
1
7098
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
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.