473,668 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serializable class

Hi

What is a Serializable class compared to a normal class?

Thanks

Regards
Nov 20 '05 #1
2 4408
i think it means you can use the serializer to persist the data
to an xml file

not sure how to do that or even how to get the samples to work

"John" <jo**@nospam.in fovis.co.uk> wrote in message
news:OB******** *****@tk2msftng p13.phx.gbl...
Hi

What is a Serializable class compared to a normal class?

Thanks

Regards

Nov 20 '05 #2
In ASP.NET I've found you cannot store a class in a session or viewstate
variable without first marking it as Serializable.

Example:
<Serializable() >_
Public Class Foo
End Class

In a Windows Form if you mark a class Serializable you can save/load it to
disk with code like this:

' class to persist to disk...
<Serializable() > _
Public Class UserSettings
Private _username As String

Public Property UserName() As String
Get
Return _username.ToLow er
End Get
Set(ByVal Value As String)
_username = Value.ToLower
End Set
End Property

End Class

' helper class to save/load form disk...
Imports System
Imports System.IO
Imports System.Runtime. Serialization.F ormatters.Binar y
Public Class UserSettingsDB
Private Sub New()
End Sub

Public Shared Function LoadSettings() As UserSettings

Dim mySettings As New UserSettings

Dim s As String = "c:\myapp.b in"

If File.Exists(s) Then

Dim streamOut As FileStream

Try
Dim formatter As New BinaryFormatter

streamOut = New FileStream(s, FileMode.Open,
FileAccess.Read )

mySettings = CType(formatter .Deserialize(st reamOut),
UserSettings)

Catch

Finally
streamOut.Close ()
End Try
End If

Return mySettings

End Function

Public Shared Sub SaveSettings(By Val mySettings As UserSettings)

Dim s As String = "c:\myapp.b in"

Dim formatter As New BinaryFormatter

Dim streamIn As New FileStream(s, FileMode.Create ,
FileAccess.Writ e)

formatter.Seria lize(streamIn, mySettings)

streamIn.Close( )

End Sub

End Class

Greg
"john m" <jm@haengineers .com> wrote in message
news:eK******** ******@TK2MSFTN GP12.phx.gbl...
i think it means you can use the serializer to persist the data
to an xml file

not sure how to do that or even how to get the samples to work

"John" <jo**@nospam.in fovis.co.uk> wrote in message
news:OB******** *****@tk2msftng p13.phx.gbl...
Hi

What is a Serializable class compared to a normal class?

Thanks

Regards


Nov 20 '05 #3

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

Similar topics

8
6299
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. Is there a document, or can some one list those types that are not serializable and the syntax for converting them? Thanks
2
3846
by: jeffpriz | last post by:
I'm having trouble.. I created a small class that I pass to my Pages, and I want to put that class into Viewstate.. I do: Viewstate.add("thisVar", myClassVariable) and i receive the lovely message that: "my class" must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate.
9
3819
by: Developer | last post by:
Hi, How can one tell wsdl.exe/VS.NET web service proxy generatioon to to put on imported classes? For example, i fin your web service you use a class: class Data { }
2
14929
by: Frank Uray | last post by:
Hi again I have a little problem with "serializable" a control ... I am creating AppDomain, Assembly and Instance. All works fine. My "base" class for the instance inherit from: - System.MarshalByRefObject - and also my Interface. In my "base" class I refer to a Form. I am able to access the form but not the controls. I get the exeption:
1
8704
by: cpnet | last post by:
I have a DataTable defined in a strongly-typed DataSet: public class MyDataSet: DataSet... { ... public class MyDataTable: DataTable... { ...}
1
1566
by: MrFile | last post by:
My company has developed a backend component which needs to be carried around in session state, therefore it must be marked at the class level. The problem I have with this is that now any class that this class uses must also be marked as serializable. This is a huge pain since now we have a dozen classes marked. Can someone better explain why we have to chain mark the supporting classes in the first place? Also, does marking all...
3
1815
by: Techno_Dex | last post by:
I'm wanting to create a Wrapper (or Extender depending on how you look at it) for a Serializable object that I then want to send over a webservice. Basically I want to create a Serializable Object, which has some properties on it, but I want to make one of the Properties a generic type that I can assign one of multiple Serializable object. I've look at creating it using an XmlNode and an object but so far both appear to have issues. I've...
4
16898
by: mark4asp | last post by:
I need to add an item to this class which I would like to be public IncumbentManager List<int>; (alternatively it may be an arraylist, but I prefer a List<int>) This is the simplifed code below for the Class: ActivityData with just two variables: ActivityID, ClosingDate. How do I deal with this in the constructor?
2
197
by: shapper | last post by:
Hello, I am using ASP.NET Membership and I know each class that I add to Profile must be Serializable: public class Contacts { public string Address { get; set; } }
0
8890
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...
1
8577
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
8653
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
7398
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...
0
5677
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
4202
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...
0
4376
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1783
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.