473,761 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml serialization using generic list fails

I've got a gaming framework i'm building and i want to save myself the
trouble of reading and writting the complete game data to a custom file
and load/save it to an XML file but i'm getting problem serializing my
stuff to XML when it comes to collections.

I'm currently using .net2 with generic lists to prevent users putting
all sorts of stuff in the arrays (Although im sure i'll be the only
user of the classes but not the game, anyway).

So i need to be able to serialize a complex object structure that looks
like this (simplified) :

Game
- Hero
- InitialDirectio n
- Scenes
- Parts
- Directions

I am able to serialize the Direction object or Hero object fine (Hero
object contains sub objects like weapon, armor and options but no
collection and everything serializes fine, but when i get to the Scenes
or Parts collection properties it simply fails stating that there was
an error serializing the Scene object.

I have empty constructors and the attributes seem to be set ok, so
here's the code for that seems to fail:

GAME.VB

''' <summary>
''' Represents a complete game you can play
''' </summary>
<XmlRoot(Elemen tName:="Game")_
Public Class Game

''' <summary>
''' Represents a complete game you can play
''' </summary>
Public Sub New()
End Sub

''' <summary>
''' Contains the scene in the game
''' </summary>
<XmlArray(Eleme ntName:="Scenes "),
XmlArrayItem(El ementName:="Sce ne", Type:=GetType(E nvironments.Sce ne))>
_
Public Property Scenes() As Generic.List(Of Environments.Sc ene)
Get
Return pScenes
End Get
Set(ByVal value As Generic.List(Of Environments.Sc ene))
pScenes = value
End Set
End Property

End Class

SCENE.VB (Complete code)

Imports System.Xml.Seri alization

''' <summary>
''' Englobes several parts to make up scenes in your game
''' </summary>
Public Class Scene

Private pName As String
Private pCodeName As String
Private pParts As New Generic.List(Of Part)

''' <summary>
''' Describes a scene that the user can go through
''' </summary>
Public Sub New()
End Sub

''' <summary>
''' Describes a scene that the user can go through
''' </summary>
''' <param name="Name">Nam e of the part being displayed</param>
''' <param name="CodeName" >Codename of the part being
displayed</param>
Public Sub New(ByVal Name As String, ByVal CodeName As String)
Me.Name = Name
Me.CodeName = CodeName
End Sub

''' <summary>
''' Contains the visual name of the scene
''' </summary>
<XmlElement(Ele mentName:="Name ")_
Public Property Name() As String
Get
Return pName
End Get
Set(ByVal value As String)
pName = value
End Set
End Property

''' <summary>
''' Contains the codename of this scene used in direction
references
''' </summary>
<XmlElement(Ele mentName:="Code Name")_
Public Property CodeName() As String
Get
Return pCodeName
End Get
Set(ByVal value As String)
pCodeName = value
End Set
End Property

''' <summary>
''' Contains the different directions available from this part to
another part
''' </summary>
<XmlArray(Eleme ntName:="Parts" ), XmlArrayItem(El ementName:="Par t",
Type:=GetType(P art))_
Public Property Parts() As Generic.List(Of Part)
Get
Return pParts
End Get
Set(ByVal value As Generic.List(Of Part))
pParts = value
End Set
End Property

End Class

PART.VB

Imports System.Xml.Seri alization

''' <summary>
''' Describes a part of a scene that the user can go through
''' </summary>
Public Class Part

Private pName As String
Private pCodeName As String
Private pDescription As String
Private pDirections As New Generic.List(Of Direction)
Private pEncounter As Creatures.Figth er
Private pOptions As New Options()

''' <summary>
''' Describes a part of a scene that the user can go through
''' </summary>
Public Sub New()
End Sub

''' <summary>
''' Describes a part of a scene that the user can go through
''' </summary>
''' <param name="Name">Nam e of the part being displayed</param>
''' <param name="CodeName" >Codename of the part being
displayed</param>
''' <param name="Descripti on">Descripti on of the part</param>
Public Sub New(ByVal Name As String, ByVal CodeName As String,
ByVal Description As String)
Me.Name = Name
Me.CodeName = CodeName
Me.Description = Description
End Sub

''' <summary>
''' Contains the visual name of the part
''' </summary>
<XmlElement(Ele mentName:="Name ")_
Public Property Name() As String
Get
Return pName
End Get
Set(ByVal value As String)
pName = value
End Set
End Property

''' <summary>
''' Contains the codename of this part used in direction references
''' </summary>
<XmlElement(Ele mentName:="Code Name")_
Public Property CodeName() As String
Get
Return pCodeName
End Get
Set(ByVal value As String)
pCodeName = value
End Set
End Property

''' <summary>
''' Main description of events happening in this part
''' </summary>
<XmlElement(Ele mentName:="Desc ription")_
Public Property Description() As String
Get
Return pDescription
End Get
Set(ByVal value As String)
pDescription = value
End Set
End Property

''' <summary>
''' Contains the different directions available from this part to
another part
''' </summary>
<XmlArray(Eleme ntName:="Direct ions"),
XmlArrayItem(El ementName:="Dir ection", Type:=GetType(D irection))_
Public Property Directions() As Generic.List(Of Direction)
Get
Return pDirections
End Get
Set(ByVal value As Generic.List(Of Direction))
pDirections = value
End Set
End Property

''' <summary>
''' Contains the encounter if any
''' </summary>
<XmlElement(Ele mentName:="Enco unter")_
Public Property Encounter() As Creatures.Figth er
Get
Return pEncounter
End Get
Set(ByVal value As Creatures.Figth er)
pEncounter = value
End Set
End Property

''' <summary>
''' Contains the environment options of this part
''' </summary>
<XmlElement(Ele mentName:="Opti ons")_
Public Property Options() As Options
Get
Return pOptions
End Get
Set(ByVal value As Options)
pOptions = value
End Set
End Property

End Class

DIRECTION.VB

Imports System.Xml.Seri alization

''' <summary>
''' Directs the user towards another portion of story
''' </summary>
Public Class Direction

Private pScene As String
Private pPart As String
Private pName As String

''' <summary>
''' Directs the user towards another portion of story
''' </summary>
Public Sub New()
End Sub

''' <summary>
''' Directs the user towards another portion of story
''' </summary>
''' <param name="Scene">Co dename of the scene to go to</param>
''' <param name="Part">Cod ename of the part to go to</param>
''' <param name="Name">Nam e of this direction</param>
Public Sub New(ByVal Scene As String, ByVal Part As String, ByVal
Name As String)
Me.Scene = Scene
Me.Part = Part
Me.Name = Name
End Sub

''' <summary>
''' Codename of the scene to go to
''' </summary>
<XmlElement(Ele mentName:="Scen e")_
Public Property Scene() As String
Get
Return pScene
End Get
Set(ByVal value As String)
pScene = value
End Set
End Property

''' <summary>
''' Codename of the part to go to
''' </summary>
<XmlElement(Ele mentName:="Part ")_
Public Property Part() As String
Get
Return pPart
End Get
Set(ByVal value As String)
pPart = value
End Set
End Property

''' <summary>
''' Name of this direction
''' </summary>
<XmlElement(Ele mentName:="Name ")_
Public Property Name() As String
Get
Return pName
End Get
Set(ByVal value As String)
pName = value
End Set
End Property

End Class
-------------------

So please just tell me what's wrong and i'll fix it, but sincerely, i'd
really like and apreciate a explanation so i can understand what is
wrong

Sep 10 '06 #1
0 5928

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

Similar topics

2
2508
by: Robert Magnusson | last post by:
Hi all, I have a healthy class defined that happily serializes and deserializes from the underlying XML file. The problem I hit is that, as soon as I add an implicit conversion in any of the classes (I'm converting from my class into OleDbParameter), the deserialization fails. The following is the error displayed when the code fails during ASPX (C#) processing:
3
1939
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects to attributes in tags (think Style tag -> Style object). The problem that I am chasing is: Html side:
2
9109
by: Justin Crites | last post by:
I have an object which I want to be serializable. I have marked with with . The object only has a single data member, which is a LinkedList<int>. This linked list is a private member and cannot be exposed publically without violating encapsulation of the class. If I make the class derive from ISerializable and IDeserializationCallback, I can attempt to "forward" these methods onto the linked list. For example (assuming _list is our...
5
6030
by: Harold Howe | last post by:
I am having a problem deserializing objects from a library when the following conditions exist: 1- The library is strongly named 2- The serialized file was created with version 1.0 of the assembly 3- I am trying to deserialize from an EXE that references version 2.0 of the assembly 4- Both version 1.0 and 2.0 of the assembly reside in the GAC (no policy redirects exist).
3
15396
by: Ympostor | last post by:
Hello. I am using attribute for redefining the element name used in XML Serialization, but it only works for the parent elemnt: Simple test code (referencing System.Xml): using System; using System.Collections.Generic; using System.Text; using System.Xml.Serialization;
1
7012
by: chrisfost | last post by:
Is it possible by using attributes to serialize a <List<List<Point>> property to output as shown below? Current Output <PolyPolyline> <ArrayOfPoint> <Point> <X>5</X> <Y>5</Y>
2
1630
by: Norman Chong | last post by:
Hiddeldi ho, I want to save an object so that I can use its content after I restart my program. I tried to solve this with serialization because someone told me that this is the correct way for this. So I wrote the following code to serialize\deserialize the object, but now I have the problem that the object has a generic list and when I'm trying to deserialize it, I get an error. <System.Serializable()Public Class TestClass
2
3845
by: Peter Duniho | last post by:
I've been learning about mechanisms .NET offers to export data. The initial goal is to see what sorts of ways are available to save an application's state (document, internal database, whatever). Not counting storing data in a database (which is obviously suitable for some things, but not necessary or even necessarily desirable for other things), here's what I've explored: Serializable attribute, with BinaryFormatter and SoapFormatter...
12
3080
by: =?Utf-8?B?enRSb24=?= | last post by:
Hi all, I recently came across something really strange and after a couple of days of debugging, I finally nailed the cause of it. However, I have absolutely no idea what I am doing wrong or is it just a bug in binary serialization. The following is a simple example of the code:
0
9538
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9909
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9788
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8794
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7342
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6623
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3889
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 we have to send another system
3
3481
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.