473,605 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serialize class with hashtable

Hello,

I'm trying to serialize a class with a Hashtable within:

' Class code:
Imports System.Collecti ons
Class clsOptions
Public countID As Integer
Public persons As New Hashtable
End Class

'Main app code:
Dim serializer As XmlSerializer = New XmlSerializer(G etType(clsOptio ns))
This doesn't work.
I've read something in the helpfiles that I have to add a count property and
add method, because Hashtable implements IList.
But I have no clue what is needed.
Nov 21 '05 #1
5 2681
"Dick" <Di**@nospam.co m> wrote in message news:<eG******* *******@TK2MSFT NGP10.phx.gbl>. ..
Hello,

I'm trying to serialize a class with a Hashtable within:

' Class code:
Imports System.Collecti ons
Class clsOptions
Public countID As Integer
Public persons As New Hashtable
End Class

'Main app code:
Dim serializer As XmlSerializer = New XmlSerializer(G etType(clsOptio ns))
This doesn't work.
I've read something in the helpfiles that I have to add a count property and
add method, because Hashtable implements IList.
But I have no clue what is needed.
You must put atribuite before class declaration
<Serializable() > Class clsOptions private countID As Integer
private persons As Hashtable public sub new
persons =new Hashtable

end sub End Class

Nov 21 '05 #2
Thanks a lot!
I will try it.

"Oldkrot" <ol*******@hotm ail.com> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
"Dick" <Di**@nospam.co m> wrote in message

news:<eG******* *******@TK2MSFT NGP10.phx.gbl>. ..
Hello,

I'm trying to serialize a class with a Hashtable within:

' Class code:
Imports System.Collecti ons
Class clsOptions
Public countID As Integer
Public persons As New Hashtable
End Class

'Main app code:
Dim serializer As XmlSerializer = New XmlSerializer(G etType(clsOptio ns))
This doesn't work.
I've read something in the helpfiles that I have to add a count property and add method, because Hashtable implements IList.
But I have no clue what is needed.


You must put atribuite before class declaration
<Serializable() > Class clsOptions
private countID As Integer
private persons As Hashtable

public sub new
persons =new Hashtable

end sub
End Class

Nov 21 '05 #3
It din't work like that.

Find a solution though:
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

"Oldkrot" <ol*******@hotm ail.com> wrote in message
news:3c******** *************** ***@posting.goo gle.com...
"Dick" <Di**@nospam.co m> wrote in message

news:<eG******* *******@TK2MSFT NGP10.phx.gbl>. ..
Hello,

I'm trying to serialize a class with a Hashtable within:

' Class code:
Imports System.Collecti ons
Class clsOptions
Public countID As Integer
Public persons As New Hashtable
End Class

'Main app code:
Dim serializer As XmlSerializer = New XmlSerializer(G etType(clsOptio ns))
This doesn't work.
I've read something in the helpfiles that I have to add a count property and add method, because Hashtable implements IList.
But I have no clue what is needed.


You must put atribuite before class declaration
<Serializable() > Class clsOptions
private countID As Integer
private persons As Hashtable

public sub new
persons =new Hashtable

end sub
End Class

Nov 21 '05 #4


serialization functions
Imports System.IO
Imports System

''' <summary>
''' this class in charge of all operations with reaction <database>
''' </summary>
Public Class clsDataServices

''' <summary>
''' load relation data from HD
''' </summary>
Private Function LoadRelationDat a() As PluginsRelation
Dim data As PluginsRelation
Dim fs As FileStream
Try
fs = New FileStream(rela tionPath, FileMode.Open)
Dim bf As New
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er
data = CType(bf.Deseri alize(fs), PluginsRelation )
WriteToMonitor. writeDebugModeL ine("Successful ", "Load relation
data", System.Drawing. Color.Magenta)
Catch ex As Exception
WriteToMonitor. writeDebugModeL ine("Error during load relation
data", ex.Message, System.Drawing. Color.Red)
Finally
Try
fs.Close()
Catch ex1 As Exception
End Try
End Try
Return data
End Function

''' <summary>
''' save operation for relation data
''' </summary>
''' <param name="data"></param>
Private Function SaveRelationDat a(ByVal data As PluginsRelation ) As
Boolean
Dim result As Boolean = False
Dim fs As FileStream
Try
fs = New FileStream(rela tionPath, FileMode.OpenOr Create)
Dim bf As New
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er
bf.Serialize(fs , data)
WriteToMonitor. writeDebugModeL ine("Successful ", "Save relation
data", System.Drawing. Color.Magenta)
result = True
Catch ex As Exception
WriteToMonitor. writeDebugModeL ine("Error during save relation
data", ex.Message, System.Drawing. Color.Red)
Finally
Try
fs.Close()
Catch ex1 As Exception
End Try
End Try
Return result
End Function
end class
*************** *************** *************** *********
Class for serialization,i t's work this is code from my application

' ----------------------------------------------------
' Created on: 05/04/2003
' Created by: Gregory
'
' Name: SidCamera
' Version: 1.00
' Description:Get all inform about relationship between sidname ->
camera number
'per ptz model
' ----------------------------------------------------
' Edited last on:
' Edited last by:
'
' Added/Changed:
' 1. ??????
' 2. ??????
' 3. ??????
' ----------------------------------------------------
<Serializable() > Public Class PluginsRelation
Private objPtzModelRela tionHash As Hashtable
Public Sub New()
objPtzModelRela tionHash = New Hashtable
End Sub
Public Property PluginRelations Data(ByVal plugin As
Constant.Enum.e PTZModel) As cameraRelation
Get
Return objPtzModelRela tionHash.Item(p lugin)
End Get
Set(ByVal Value As cameraRelation)
objPtzModelRela tionHash.Item(p lugin) = Value
End Set
End Property

Public Property PluginsData() As Hashtable
Get
Return objPtzModelRela tionHash
End Get
Set(ByVal Value As Hashtable)
objPtzModelRela tionHash = Value
End Set
End Property
End Class

<Serializable() > Public Class cameraRelation
Private objSidNameToSid IndexHash As Hashtable
Private objCamerasArray As clsCamera()
Private pluginID As Constant.Enum.e PTZModel

Public Property Plugin() As Constant.Enum.e PTZModel
Get
Return pluginID
End Get
Set(ByVal Value As Constant.Enum.e PTZModel)
pluginID = Value
End Set
End Property
Public Sub New(ByVal count As Integer)
objSidNameToSid IndexHash = Hashtable.Synch ronized(New Hashtable)
ReDim objCamerasArray (count - 1)
End Sub
'************** *************** *************** *************** ********
' created by: Gregory
'input camera number, sidname
' adding camera to hashtable for building relationship between
' sid -> physical camera number
' History:
' 1.
' 2.
'************** *************** *************** *************** *********

Public Overloads Sub AddCamera(ByVal Sid As String, ByVal
cameraNumber As Int32)
Try
Dim index As Integer
Dim camera As clsCamera
Try
If objSidNameToSid IndexHash.Conta insKey(Sid) Then
index = objSidNameToSid IndexHash.Item( Sid)
camera = New clsCamera
With camera
.Camera = cameraNumber
.Index = index
.Name = Sid
End With
objCamerasArray (index) = camera
End If
Catch ex As Exception

End Try
Catch ex As Exception
ExceptionManage ment.ExceptionM anager.Publish( ex)
End Try
End Sub

Public Overloads Sub AddCamera(ByVal SidName As String, ByVal
sidIndex As Integer, ByVal cameraNumber As Int32)
Try
Dim index As Integer
Dim camera As clsCamera
Try
If objSidNameToSid IndexHash.Conta insKey(SidName) Then
camera = New clsCamera
With camera
.Camera = cameraNumber
.Index = sidIndex
.Name = SidName
End With
objCamerasArray (sidIndex) = camera
objSidNameToSid IndexHash.Item( SidName) = sidIndex
End If
Catch ex As Exception

End Try
Catch ex As Exception
ExceptionManage ment.ExceptionM anager.Publish( ex)
End Try
End Sub

Public Sub RemoveCamera(By Val SidName As String)
Try
Dim index As Integer
Try
If objSidNameToSid IndexHash.Conta insKey(SidName) Then
index = objSidNameToSid IndexHash.Item( SidName)
objCamerasArray (index) = Nothing
End If
Catch ex As Exception
End Try
Catch ex As Exception
ExceptionManage ment.ExceptionM anager.Publish( ex)
End Try
End Sub

'************** *************** *************** *************** ********
' created by: Gregory
'sid object
' getting physical camera from hashtable
' sid -> physical camera number
' History:
' 1.
' 2.
'************** *************** *************** *************** *********
Public Overloads Function getCameraNumber (ByVal sid As Integer) As
Integer
Dim cameraNumber As Integer = -1
Dim camera As clsCamera
Try
camera = objCamerasArray (sid)
If Not camera Is Nothing Then
cameraNumber = camera.Camera
End If
Catch ex As Exception
ExceptionManage ment.ExceptionM anager.Publish( ex)
End Try
Return cameraNumber
End Function

Public Overloads Function getCameraNumber (ByVal sid As String) As
Integer
Dim cameraNumber = -1, index As Integer
Dim camera As clsCamera
Try
If objSidNameToSid IndexHash.Conta insKey(sid) Then
index = objSidNameToSid IndexHash.Item( sid)
camera = objCamerasArray (index)
If Not camera Is Nothing Then
cameraNumber = camera.Camera
End If
End If
Catch ex As Exception
ExceptionManage ment.ExceptionM anager.Publish( ex)
End Try
Return cameraNumber
End Function

Public Property SidNameToSidInd ex() As Hashtable
Get
Return objSidNameToSid IndexHash
End Get
Set(ByVal Value As Hashtable)
objSidNameToSid IndexHash = Value
End Set
End Property

Public Property getCameras() As clsCamera()
Get
Return objCamerasArray
End Get
Set(ByVal Value As clsCamera())
objCamerasArray = Value
End Set
End Property
End Class

<Serializable() > Public Class clsCamera
Private sidIndex As Integer
Private cameraNumber As Integer
Private cameraName As String

Public Sub New()
End Sub
Public Property Index() As Integer
Get
Return sidIndex
End Get
Set(ByVal Value As Integer)
sidIndex = Value
End Set
End Property

Public Property Camera() As Integer
Get
Return cameraNumber
End Get
Set(ByVal Value As Integer)
cameraNumber = Value
End Set
End Property

Public Property Name() As String
Get
Return cameraName
End Get
Set(ByVal Value As String)
cameraName = Value
End Set
End Property
End Class

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
And this variant use xml serialization
Private Function SaveRelationDat a(ByVal data As PluginsRelation ) As
Boolean
Dim result As Boolean = False
Dim fs As FileStream
Try
fs = New FileStream(rela tionPath, FileMode.OpenOr Create)
'Dim bf As New
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er
Dim bf As New
System.Runtime. Serialization.F ormatters.Soap. SoapFormatter
bf.Serialize(fs , data)
WriteToMonitor. writeDebugModeL ine("Successful ", "Save relation
data", System.Drawing. Color.Magenta)
result = True
Catch ex As Exception
WriteToMonitor. writeDebugModeL ine("Error during save relation
data", ex.Message, System.Drawing. Color.Red)
Finally
Try
fs.Close()
Catch ex1 As Exception
End Try
End Try
Return result
End Function

Reagards OldKrot

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #6

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

Similar topics

5
24689
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
0
216
by: Arjen | last post by:
Hello, I have made a little test application and needs some help. I have two classes with hash tables which I want to serialize inside one xml file. My question is if someone can make the code complete? (loading and saving) - I have made some starting points. - The // comment tags says where to do "something". - What the "something" means I don't know... but I have tried...
0
1071
by: Arjen | last post by:
Hello, I have made a little test application and needs some help. I have two classes with hash tables which I want to serialize inside one xml file. My question is if someone can make the code complete? (loading and saving) - I have made some starting points. - The // comment tags says where to do "something". - What the "something" means I don't know... but I have tried...
2
819
by: Diego F. | last post by:
I need to serialize a hash table in a file (xml or other), but I'm new with all this and I don't know how to serialize. Can you put me a piece of code to do this? Regards, Diego F.
2
2310
by: MichiSu11 | last post by:
I want to serialize the properties of controls. I write Property Name and Value to an Hashtable. This hashtable is serialized. So I want to find out which properties of the control are serializable. I tried following but it doesn't work. I still get not serializable properties into my hashtable. Exception of System.Runtime.Serialization.SerializationException is not marked as serializable PropertyInfo pi Type t t=ctl.GetType() ...
1
3717
by: Bill L | last post by:
Hi guys, Because of restarting application after new DLLs installed into \Bin folder , we move the session to StateServer, everything'a alright except when I try to write any simple hash table into session. The Error message shows like ---------------------------------------------------------------------------- ----- Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not...
1
3931
by: Raed Sawalha | last post by:
we have already built Web Application,we did changes on in class in application so , we need to pass a Hashtable object to a webserivce, we're using XML Serialization , my problem in how to serialize the Hastable in order to pass it to a webservice. the class: public class MessageClass {
7
3533
by: Ben Amada | last post by:
I've created a class that I need to store in ViewState. However when I try to store it in ViewState, I get the following error: "The type 'solution.pe2' must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate." I've included the <Serializable()> attribute, but I'm still getting the same error. The class is below ... as you can see it contains a Collection, two
6
2628
by: Joe | last post by:
Hello All, I want to serialize a hashtable to a database table to persist its values between postbacks. The client requires that I not use ViewState, hence the database. The samples in MSDN show how to serialize a class that implements the ICollection interface to a file. Does anyone know how to serialize to a database table and conversely de-serialize from the table?
0
7999
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...
0
8423
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8411
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6740
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
5885
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
3911
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2437
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
1
1530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1270
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.