Showing posts with label serialization. Show all posts
Showing posts with label serialization. Show all posts

Monday, March 26, 2012

serializable in asp.net?

I am developing a web application in asp.net 2.0. I have not used serialization in the past. can i still use it even if I am not going to pass the object from one machine to another.
is it kind of a good practice to have [Serializable] on top of the methods anyways?

[Serializable]_
public class PayeeData
{
...
}

I don't see that marking classes as serializable hurts anything, but you only need to so mark it if it's going to be serialized. Often this is only done when you use the session state server:

<sessionState mode="StateServer" etc

I don't mark them as serializable unless I get an error that an object isn't serializable


hello

sahajMarg:

is it kind of a good practice to have [Serializable] on top of the methods anyways?

Sure , its recommened to Mark your class as [Serializable], so that you avoid any failures if you decide to use OOP( out of process) session mode( SQlserver OR state server).

also marking your classes as [Serializable] enables you to pass them through webservices Or to make them as Remote Objects.

i recommened also to exclude the calculated public properties from serialization by marking them with XmlIgnore() attribute


<Serializable()> _Public Class CustomerPrivate _IDAs Integer Public Property ID()As Integer Get Return _IDEnd Get Set(ByVal valueAs Integer) _ID = valueEnd Set End Property Private _nameAs String Public Property Name()As String Get Return _nameEnd Get Set(ByVal valueAs String) _name = valueEnd Set End Property Private _dateOfBirthAs DateTimePublic Property DateOfBirth()As DateTimeGet Return _dateOfBirthEnd Get Set(ByVal valueAs DateTime) _dateOfBirth = valueEnd Set End Property' calculated proeprty , no need to serialize it <System.Xml.Serialization.XmlIgnore()> _Public ReadOnly Property Age()As Integer Get Return Now.Subtract(_dateOfBirth).Days / 365End Get End PropertyEnd Class

thanks anas...

Serialization

Hi Guys
I want to understand Serialization.
What is serialization.
When do we need to use'
What are advantages and Divantages.
Also please diret me to some good sites on serialization.
Thanks for all ur help.
Thanks
vinaySerialization is the process of taking an object in memory and turning it to
something that can be written out to a stream (file, network stream, etc).
For example, if a web service returns a dataset, that dataset objects needs
to be serialized into XML, and then deserialized back into a dataset object
on the client.
I recommed just searching google for site for more info.
"vinay" <vinay@.discussions.microsoft.com> wrote in message
news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> Hi Guys
> I want to understand Serialization.
> What is serialization.
> When do we need to use'
> What are advantages and Divantages.
> Also please diret me to some good sites on serialization.
> Thanks for all ur help.
> Thanks
> vinay
Hi vinay,
The simplest way to describe serialization is the process of converting
binary objects to text.
Most often in .Net, this is done by converting objects to XML.
Serialization is used with SOAP, for converting objects into XML in order to
transmit them over the Internet via SOAP (Simple Object Access Protocol). It
is also useful for cross-platform compatibility, as text is text on any
platform.
Generally speaking, at the other end, XML is de-serialized back into binary
objects.
The advantage of serialzation is the ability to transmit data across a
network in a cross-platform-compatible format, as well as saving it in a
storage medium in a non-proprietary format.
The chief divantage is the overhead involved in serializing and
de-serializing data, as well as latency issues with transmitting text over a
TCP network.
You can read lots more about serialization by following the following URL:
http://search.microsoft.com/search/.../>
4&s=1&swc=4
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"vinay" <vinay@.discussions.microsoft.com> wrote in message
news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> Hi Guys
> I want to understand Serialization.
> What is serialization.
> When do we need to use'
> What are advantages and Divantages.
> Also please diret me to some good sites on serialization.
> Thanks for all ur help.
> Thanks
> vinay
In serialization, does it save to the HardDisk or is always in the Memory'
"Marina" wrote:

> Serialization is the process of taking an object in memory and turning it
to
> something that can be written out to a stream (file, network stream, etc).
> For example, if a web service returns a dataset, that dataset objects need
s
> to be serialized into XML, and then deserialized back into a dataset objec
t
> on the client.
> I recommed just searching google for site for more info.
> "vinay" <vinay@.discussions.microsoft.com> wrote in message
> news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
>
>
It's irrelevant where it gets saved to. The example I gave with web service
was transporting an object over the internet. But you could just as easily
have something serialized to a file. Like I said, you can think of
serialization working on streams - and there are many different kidns of
streams.
"vinay" <vinay@.discussions.microsoft.com> wrote in message
news:FD0504FB-8BE4-4329-B217-DB5D624F905F@.microsoft.com...
> In serialization, does it save to the HardDisk or is always in the
Memory'
>
> "Marina" wrote:
>
it to
etc).
needs
object
Is a string in the hard disk, or is it in memory?
(Answer: It is wherever you put it).
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"vinay" <vinay@.discussions.microsoft.com> wrote in message
news:FD0504FB-8BE4-4329-B217-DB5D624F905F@.microsoft.com...
> In serialization, does it save to the HardDisk or is always in the
Memory'
>
> "Marina" wrote:
>
it to
etc).
needs
object
this isn't strictly true.
Serialization doesn't require text as the medium, binary serializers are
very common. In fact with .net you can pick either binary or xml when you
serialize an object.
-- bruce (sqlwork.com)
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:%23ydIb8dvEHA.1512@.TK2MSFTNGP12.phx.gbl...
> Hi vinay,
> The simplest way to describe serialization is the process of converting
> binary objects to text.
> Most often in .Net, this is done by converting objects to XML.
> Serialization is used with SOAP, for converting objects into XML in order
to
> transmit them over the Internet via SOAP (Simple Object Access Protocol).
It
> is also useful for cross-platform compatibility, as text is text on any
> platform.
> Generally speaking, at the other end, XML is de-serialized back into
binary
> objects.
> The advantage of serialzation is the ability to transmit data across a
> network in a cross-platform-compatible format, as well as saving it in a
> storage medium in a non-proprietary format.
> The chief divantage is the overhead involved in serializing and
> de-serializing data, as well as latency issues with transmitting text over
a
> TCP network.
> You can read lots more about serialization by following the following URL:
>
[url]http://search.microsoft.com/search/results.aspx?qu=serialization&View=msdn&st=b&c=4&s=1&swc=4[/ur
l]
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
> "vinay" <vinay@.discussions.microsoft.com> wrote in message
> news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
>
Thanks for the correction again, bruce.
Yes, serialization can be binary.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"bruce barker" <nospam_brubar@.safeco.com> wrote in message
news:#sGbATfvEHA.536@.TK2MSFTNGP11.phx.gbl...
> this isn't strictly true.
> Serialization doesn't require text as the medium, binary serializers are
> very common. In fact with .net you can pick either binary or xml when you
> serialize an object.
> -- bruce (sqlwork.com)
>
> "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> news:%23ydIb8dvEHA.1512@.TK2MSFTNGP12.phx.gbl...
order
> to
Protocol).
> It
> binary
over
> a
URL:
>
[url]http://search.microsoft.com/search/results.aspx?qu=serialization&View=msdn&st=b&c=4&s=1&swc=4[/ur
l]
>
Thanks guys.
"Kevin Spencer" wrote:

> Thanks for the correction again, bruce.
> Yes, serialization can be binary.
> --
> HTH,
> Kevin Spencer
> ..Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
> "bruce barker" <nospam_brubar@.safeco.com> wrote in message
> news:#sGbATfvEHA.536@.TK2MSFTNGP11.phx.gbl...
> order
> Protocol).
> over
> URL:
> http://search.microsoft.com/search/...
c=4&s=1&swc=4
>
>

Serialization

Hi Guys

I want to understand Serialization.

What is serialization.
When do we need to use??
What are advantages and Disadvantages.

Also please diret me to some good sites on serialization.
Thanks for all ur help.

Thanks
vinaySerialization is the process of taking an object in memory and turning it to
something that can be written out to a stream (file, network stream, etc).

For example, if a web service returns a dataset, that dataset objects needs
to be serialized into XML, and then deserialized back into a dataset object
on the client.

I recommed just searching google for site for more info.

"vinay" <vinay@.discussions.microsoft.com> wrote in message
news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> Hi Guys
> I want to understand Serialization.
> What is serialization.
> When do we need to use??
> What are advantages and Disadvantages.
> Also please diret me to some good sites on serialization.
> Thanks for all ur help.
> Thanks
> vinay
Hi vinay,

The simplest way to describe serialization is the process of converting
binary objects to text.

Most often in .Net, this is done by converting objects to XML.

Serialization is used with SOAP, for converting objects into XML in order to
transmit them over the Internet via SOAP (Simple Object Access Protocol). It
is also useful for cross-platform compatibility, as text is text on any
platform.

Generally speaking, at the other end, XML is de-serialized back into binary
objects.

The advantage of serialzation is the ability to transmit data across a
network in a cross-platform-compatible format, as well as saving it in a
storage medium in a non-proprietary format.

The chief disadvantage is the overhead involved in serializing and
de-serializing data, as well as latency issues with transmitting text over a
TCP network.

You can read lots more about serialization by following the following URL:

http://search.microsoft.com/search/...b&c=4&s=1&swc=4

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"vinay" <vinay@.discussions.microsoft.com> wrote in message
news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> Hi Guys
> I want to understand Serialization.
> What is serialization.
> When do we need to use??
> What are advantages and Disadvantages.
> Also please diret me to some good sites on serialization.
> Thanks for all ur help.
> Thanks
> vinay
In serialization, does it save to the HardDisk or is always in the Memory??

"Marina" wrote:

> Serialization is the process of taking an object in memory and turning it to
> something that can be written out to a stream (file, network stream, etc).
> For example, if a web service returns a dataset, that dataset objects needs
> to be serialized into XML, and then deserialized back into a dataset object
> on the client.
> I recommed just searching google for site for more info.
> "vinay" <vinay@.discussions.microsoft.com> wrote in message
> news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> > Hi Guys
> > I want to understand Serialization.
> > What is serialization.
> > When do we need to use??
> > What are advantages and Disadvantages.
> > Also please diret me to some good sites on serialization.
> > Thanks for all ur help.
> > Thanks
> > vinay
>
It's irrelevant where it gets saved to. The example I gave with web service
was transporting an object over the internet. But you could just as easily
have something serialized to a file. Like I said, you can think of
serialization working on streams - and there are many different kidns of
streams.

"vinay" <vinay@.discussions.microsoft.com> wrote in message
news:FD0504FB-8BE4-4329-B217-DB5D624F905F@.microsoft.com...
> In serialization, does it save to the HardDisk or is always in the
Memory??
>
> "Marina" wrote:
> > Serialization is the process of taking an object in memory and turning
it to
> > something that can be written out to a stream (file, network stream,
etc).
> > For example, if a web service returns a dataset, that dataset objects
needs
> > to be serialized into XML, and then deserialized back into a dataset
object
> > on the client.
> > I recommed just searching google for site for more info.
> > "vinay" <vinay@.discussions.microsoft.com> wrote in message
> > news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> > > Hi Guys
> > > > I want to understand Serialization.
> > > > What is serialization.
> > > When do we need to use??
> > > What are advantages and Disadvantages.
> > > > Also please diret me to some good sites on serialization.
> > > Thanks for all ur help.
> > > > Thanks
> > > vinay
Is a string in the hard disk, or is it in memory?

(Answer: It is wherever you put it).

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"vinay" <vinay@.discussions.microsoft.com> wrote in message
news:FD0504FB-8BE4-4329-B217-DB5D624F905F@.microsoft.com...
> In serialization, does it save to the HardDisk or is always in the
Memory??
>
> "Marina" wrote:
> > Serialization is the process of taking an object in memory and turning
it to
> > something that can be written out to a stream (file, network stream,
etc).
> > For example, if a web service returns a dataset, that dataset objects
needs
> > to be serialized into XML, and then deserialized back into a dataset
object
> > on the client.
> > I recommed just searching google for site for more info.
> > "vinay" <vinay@.discussions.microsoft.com> wrote in message
> > news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> > > Hi Guys
> > > > I want to understand Serialization.
> > > > What is serialization.
> > > When do we need to use??
> > > What are advantages and Disadvantages.
> > > > Also please diret me to some good sites on serialization.
> > > Thanks for all ur help.
> > > > Thanks
> > > vinay
this isn't strictly true.

Serialization doesn't require text as the medium, binary serializers are
very common. In fact with .net you can pick either binary or xml when you
serialize an object.

-- bruce (sqlwork.com)

"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:%23ydIb8dvEHA.1512@.TK2MSFTNGP12.phx.gbl...
> Hi vinay,
> The simplest way to describe serialization is the process of converting
> binary objects to text.
> Most often in .Net, this is done by converting objects to XML.
> Serialization is used with SOAP, for converting objects into XML in order
to
> transmit them over the Internet via SOAP (Simple Object Access Protocol).
It
> is also useful for cross-platform compatibility, as text is text on any
> platform.
> Generally speaking, at the other end, XML is de-serialized back into
binary
> objects.
> The advantage of serialzation is the ability to transmit data across a
> network in a cross-platform-compatible format, as well as saving it in a
> storage medium in a non-proprietary format.
> The chief disadvantage is the overhead involved in serializing and
> de-serializing data, as well as latency issues with transmitting text over
a
> TCP network.
> You can read lots more about serialization by following the following URL:
>
http://search.microsoft.com/search/...b&c=4&s=1&swc=4
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
> "vinay" <vinay@.discussions.microsoft.com> wrote in message
> news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> > Hi Guys
> > I want to understand Serialization.
> > What is serialization.
> > When do we need to use??
> > What are advantages and Disadvantages.
> > Also please diret me to some good sites on serialization.
> > Thanks for all ur help.
> > Thanks
> > vinay
Thanks for the correction again, bruce.

Yes, serialization can be binary.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"bruce barker" <nospam_brubar@.safeco.com> wrote in message
news:#sGbATfvEHA.536@.TK2MSFTNGP11.phx.gbl...
> this isn't strictly true.
> Serialization doesn't require text as the medium, binary serializers are
> very common. In fact with .net you can pick either binary or xml when you
> serialize an object.
> -- bruce (sqlwork.com)
>
> "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> news:%23ydIb8dvEHA.1512@.TK2MSFTNGP12.phx.gbl...
> > Hi vinay,
> > The simplest way to describe serialization is the process of converting
> > binary objects to text.
> > Most often in .Net, this is done by converting objects to XML.
> > Serialization is used with SOAP, for converting objects into XML in
order
> to
> > transmit them over the Internet via SOAP (Simple Object Access
Protocol).
> It
> > is also useful for cross-platform compatibility, as text is text on any
> > platform.
> > Generally speaking, at the other end, XML is de-serialized back into
> binary
> > objects.
> > The advantage of serialzation is the ability to transmit data across a
> > network in a cross-platform-compatible format, as well as saving it in a
> > storage medium in a non-proprietary format.
> > The chief disadvantage is the overhead involved in serializing and
> > de-serializing data, as well as latency issues with transmitting text
over
> a
> > TCP network.
> > You can read lots more about serialization by following the following
URL:
http://search.microsoft.com/search/...b&c=4&s=1&swc=4
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > I get paid good money to
> > solve puzzles for a living
> > "vinay" <vinay@.discussions.microsoft.com> wrote in message
> > news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> > > Hi Guys
> > > > I want to understand Serialization.
> > > > What is serialization.
> > > When do we need to use??
> > > What are advantages and Disadvantages.
> > > > Also please diret me to some good sites on serialization.
> > > Thanks for all ur help.
> > > > Thanks
> > > vinay
Thanks guys.

"Kevin Spencer" wrote:

> Thanks for the correction again, bruce.
> Yes, serialization can be binary.
> --
> HTH,
> Kevin Spencer
> ..Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
> "bruce barker" <nospam_brubar@.safeco.com> wrote in message
> news:#sGbATfvEHA.536@.TK2MSFTNGP11.phx.gbl...
> > this isn't strictly true.
> > Serialization doesn't require text as the medium, binary serializers are
> > very common. In fact with .net you can pick either binary or xml when you
> > serialize an object.
> > -- bruce (sqlwork.com)
> > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > news:%23ydIb8dvEHA.1512@.TK2MSFTNGP12.phx.gbl...
> > > Hi vinay,
> > > > The simplest way to describe serialization is the process of converting
> > > binary objects to text.
> > > > Most often in .Net, this is done by converting objects to XML.
> > > > Serialization is used with SOAP, for converting objects into XML in
> order
> > to
> > > transmit them over the Internet via SOAP (Simple Object Access
> Protocol).
> > It
> > > is also useful for cross-platform compatibility, as text is text on any
> > > platform.
> > > > Generally speaking, at the other end, XML is de-serialized back into
> > binary
> > > objects.
> > > > The advantage of serialzation is the ability to transmit data across a
> > > network in a cross-platform-compatible format, as well as saving it in a
> > > storage medium in a non-proprietary format.
> > > > The chief disadvantage is the overhead involved in serializing and
> > > de-serializing data, as well as latency issues with transmitting text
> over
> > a
> > > TCP network.
> > > > You can read lots more about serialization by following the following
> URL:
> > > http://search.microsoft.com/search/...b&c=4&s=1&swc=4
> > > > --
> > > HTH,
> > > Kevin Spencer
> > > .Net Developer
> > > Microsoft MVP
> > > I get paid good money to
> > > solve puzzles for a living
> > > > "vinay" <vinay@.discussions.microsoft.com> wrote in message
> > > news:2AE7EB6B-F8F1-4511-9700-0A8D85EACF71@.microsoft.com...
> > > > Hi Guys
> > > > > > I want to understand Serialization.
> > > > > > What is serialization.
> > > > When do we need to use??
> > > > What are advantages and Disadvantages.
> > > > > > Also please diret me to some good sites on serialization.
> > > > Thanks for all ur help.
> > > > > > Thanks
> > > > vinay
> > >

Serialization

Hi All
Can anyone help me out to find out the Serializable and non-
serializable object in .net framework library....Hello Deshi,
use .net reflector to find the objects with Serializable attribute
But why u need this?
If object doesnt have this attribute your can serialize it using custom seri
alization
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
D> Hi All
D>
D> Can anyone help me out to find out the Serializable and non-
D> serializable object in .net framework library....
D>

Serialization

Reading an ASP.Net book I saw the "[Serializable]" line and I do not know what they mean:

[Serializable]
public class someClass
{...}

Does that make the entire class serializable?

Many Thanks!

http://msdn2.microsoft.com/en-us/library/system.serializableattribute.aspx

-- Dan


Yes, all the members, properties and methods of the class will be serialize to the format specified..i.e. binary, xml etc..
But don't I have to implement some interface? How about some member that is not serializable?

Did you read the MSDN article? Only fields in a class are serialized when applying the SerializableAttribute meta tag. The ISerialable interface is just one way to serialize a class. If it is implemented on a class that also uses SerializableAttribute, the interface will override the process. ISerialable provides more control over how the data is serialized. You can control which fields are serialized by with SerializableAttribute by using theNonSerializedAttribute meta tag.

-- Dan

Serialization

Serialization stores state of the object i.e. member variable values to disk

i have read the articles on this but not clear with the concept anybody can clear what they are.

If you want examples where serialization is used you can for example take a look at the Profile feature of ASP.Net 2.0. When you add a property to the Profile in web.config, and for example specify your own type, Binary serialization will be used to save all the state of the current object into the data source. This will make sure you get all the objects state when you deserialize the data back again.

If you want to craete a deep clone of an object (copy the whole object), serialization can be used.


hiFredrik N thanks for the reply

i work in framework 1.1

and what do you mean by this

' to save all the state of the current object into the data source'

state of the object means ?


State in this context is the current "data" the object has at the current moment.


I hope the following articles gives u a lot of help

http://aspalliance.com/983

Serialization

Hi,

I have to serialize a class which consists of numerous members in it. I know that it can be serialized with the [Serializable] attribute. But my problem is that I wanna serialize only few members. Is there any way that allows us to serialize only few members in a class?

Please help.

Decorate the fields you want to exclude with [NonSerialized] .


You can include the [NonSerialized] attribute for the members which you do not wish to be serialized as shown below.

[Serializable]
class ABC
{
int x;
int y;
[NonSerialized]int z;//z will not be serializable.
}

I hopw this helped you.

SrikanthReddy.L

Serialization

I want to know more about serialization and how actually it is implemented in this project.

I want to have a realtime sample for using serialization

can any one give the relavant information

ganesh@dotnet.itags.org.nilgris

Depends on what you're trying to do, but theres a nice tutorial with sourcecode over at CodeProject on serialization:

http://www.codeproject.com/csharp/objserial.asp

Serialization

Greetings,


i have two applications on two separate machines

In the first application i serialize an object into a text file ,so my question how can i transmit the text file by hard coding to the second application in order to deserialize the text file into the original object?

your help is highly appreciated

best regards

Hello,

How to: Deserialize an Object :http://msdn2.microsoft.com/en-us/library/fa420a9y.aspx


Greetings,

thank you for the support

i know how can i deserialize an object but my question is how can the second application get the textfile (file1.txt where the file1.txt is a serialized object serialized by the first application machine a)?

your help is highly appreciated


You have to tell the second application where it can find the textfile. If the name of the textfile is always the same, add a key in your config file that holds the name.

If the name changes dynamically and unpredictable you'll have to find a way to pass the values. If both applications are on the same machine you may use the windows message queue or a static file in your filesystem that holds your files.

If they are on different machines you may use either a webservice or a network connection over TCP or UDP.

Hope that helps,
Matthias :)


thank you for the support

i will try.

Serialization

Can we serialize the object which uses HashTables.

It depends on the type of object that you are storing in the Hashtable.

If you are storing objects like string (or whatever which is marked with attribute serializable), then you can look thro the objects to serialize them one by one.


r.ramkumar:

Can we serialize the object which uses HashTables.

Yes, as long as the indivdual objects in the hash table are serializable (as the previous poster points out). Then all you have to do is serialize your hashtable, you don't have to loop through, serializing each individual object. If you take a look at the definition of Hashtable athttp://msdn2.microsoft.com/en-us/library/system.collections.hashtable(VS.71).aspx you'll see that it's marked as [Serializabl] and it implements the ISerializable interface.

Most objects that you would wish to put into a hashtable are serializale. An example of something that isn't is a DataReader, and if you think about it, there's no way that a DataReader could be put into a stream of text since it holds a connection to the database. Connections (to anything) are perfect examples of things that aren't serializable.

Sometimes you create a custom class and try to serialize it (or save it to an asp.net State server, which requires that it be serializable) and you get an error that it's not serializable. Just try decorating your class with the [Serializable] attribute, for example

[Serializable]
public class MyClass
{
....blah, blah
}

(note that in vb you use angle brackets instead of straight brackets, ie, <Serializable> instead of [Serializable]


I just reread your post and realize that I misunderstood it. The object you want to serialize uses a hashtable (I thought you were just trying to serialize something of type Hashtable). My answer is the same but pay special attention to the last half, the part beginning "Sometimes you create a custom class..." which I think is what will really answer your question.

Serialization

I have fair knowledge about the serialization.

But when we talk about large scale application serialization plays a vital roles in the project.

can i have a real time scenerio about this concept.

any help would be appreciated.

Any help would be more appreciated . It is pretty Urgent.


Any solutions for using serialization with a real time samples


Help is more appericated. pretty urgent

serialization - include collection property

Why the collection property is not included in the ouput
serialization ?

I have a custom generic collection (implements icollection): Events of
objects: Event.

Event is a simple class exposing, let's say, one property: name

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class

Events Implements ICollection
Public EventColor as string
......

Everything works except when I save the xml file I'm expecting to get
smth like:

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>

EVENTCOLOR attribute is not in the xml, any idea ?

Thanks,
xkeIn your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"xke" <xkeops@.gmail.comwrote in message
news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?
>
I have a custom generic collection (implements icollection): Events of
objects: Event.
>
Event is a simple class exposing, let's say, one property: name
>
Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class
>
>
Events Implements ICollection
Public EventColor as string
......
>
Everything works except when I save the xml file I'm expecting to get
smth like:
>
<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>
>
EVENTCOLOR attribute is not in the xml, any idea ?
>
Thanks,
xke
>


Hi Andrew,

Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.

It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.

Thanks,
xke

On Oct 22, 10:06 pm, "Andrew Faust" <and...@.andrewfaust.comwrote:

Quote:

Originally Posted by

In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?
>
--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com
>
"xke" <xke...@.gmail.comwrote in message
>
news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...
>
>
>

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?


>

Quote:

Originally Posted by

I have a custom generic collection (implements icollection): Events of
objects: Event.


>

Quote:

Originally Posted by

Event is a simple class exposing, let's say, one property: name


>

Quote:

Originally Posted by

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class


>

Quote:

Originally Posted by

Events Implements ICollection
Public EventColor as string
......


>

Quote:

Originally Posted by

Everything works except when I save the xml file I'm expecting to get
smth like:


>

Quote:

Originally Posted by

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>


>

Quote:

Originally Posted by

EVENTCOLOR attribute is not in the xml, any idea ?


>

Quote:

Originally Posted by

Thanks,
xke- Hide quoted text -


>
- Show quoted text -


Sorry. Misread your original post.

According to this article the Serializer only supports writing out the
actual objects contained in an ICollection and not the actual properties of
the collection itself.

http://www.diranieh.com/NETSerializ...rialization.htm
I would recommend a slight restructuring to something like this

class Events
{
public string EventColor;
private List<Eventm_Events;
public Event[] UpcomingEvents
{
get { return m_Events.ToArray(); }
set {
m_Events = new List<Event>();
m_Events.AddRange(value);
}
}
}

Then serialize the Events class.

"xke" wrote:

Quote:

Originally Posted by

Hi Andrew,
>
Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.
>
It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.
>
Thanks,
xke
>
On Oct 22, 10:06 pm, "Andrew Faust" <and...@.andrewfaust.comwrote:

Quote:

Originally Posted by

In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?

--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com

"xke" <xke...@.gmail.comwrote in message

news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?


Quote:

Originally Posted by

I have a custom generic collection (implements icollection): Events of
objects: Event.


Quote:

Originally Posted by

Event is a simple class exposing, let's say, one property: name


Quote:

Originally Posted by

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class


Quote:

Originally Posted by

Events Implements ICollection
Public EventColor as string
......


Quote:

Originally Posted by

Everything works except when I save the xml file I'm expecting to get
smth like:


Quote:

Originally Posted by

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>


Quote:

Originally Posted by

EVENTCOLOR attribute is not in the xml, any idea ?


Quote:

Originally Posted by

Thanks,
xke- Hide quoted text -


- Show quoted text -


>
>
>


beautiful idea / will give it a try tomorrow

thanks,
xke

On Oct 23, 1:28 pm, Andrew Faust <afa...@.nospam.nospamwrote:

Quote:

Originally Posted by

Sorry. Misread your original post.
>
According to this article the Serializer only supports writing out the
actual objects contained in an ICollection and not the actual properties of
the collection itself.
>
http://www.diranieh.com/NETSerializ...rialization.htm
>
I would recommend a slight restructuring to something like this
>
class Events
{
public string EventColor;
private List<Eventm_Events;
public Event[] UpcomingEvents
{
get { return m_Events.ToArray(); }
set {
m_Events = new List<Event>();
m_Events.AddRange(value);
}
}
>
}
>
Then serialize the Events class.
>
>
>
"xke" wrote:

Quote:

Originally Posted by

Hi Andrew,


>

Quote:

Originally Posted by

Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.


>

Quote:

Originally Posted by

It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.


>

Quote:

Originally Posted by

Thanks,
xke


>

Quote:

Originally Posted by

On Oct 22, 10:06 pm, "Andrew Faust" <and...@.andrewfaust.comwrote:

Quote:

Originally Posted by

In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com


>

Quote:

Originally Posted by

Quote:

Originally Posted by

"xke" <xke...@.gmail.comwrote in message


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

I have a custom generic collection (implements icollection): Events of
objects: Event.


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Event is a simple class exposing, let's say, one property: name


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Events Implements ICollection
Public EventColor as string
......


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Everything works except when I save the xml file I'm expecting to get
smth like:


>

Quote:

Originally Posted by

Quote:

Originally Posted by

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>


>

Quote:

Originally Posted by

Quote:

Originally Posted by

EVENTCOLOR attribute is not in the xml, any idea ?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Thanks,
xke- Hide quoted text -


>

Quote:

Originally Posted by

Quote:

Originally Posted by

- Show quoted text -- Hide quoted text -


>
- Show quoted text -

serialization and Session Object

Hello,
I recently read that a class must support serialization in order for it to
be stored in the Session State. Before reading this I had been storing a
class to the Session State no problem (without serialization). The class is
simply a storage class and contains only primitive types...is it necessary
to serialize this object? If so, how do you go about serializing an entire
class?
Thanks much.BTW, using C#. Thanks
"Bilbo" <Bilbo@.cox.net> wrote in message
news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I recently read that a class must support serialization in order for it to
> be stored in the Session State. Before reading this I had been storing a
> class to the Session State no problem (without serialization). The class
is
> simply a storage class and contains only primitive types...is it
necessary
> to serialize this object? If so, how do you go about serializing an entire
> class?
> Thanks much.
>
It only needs to be serializable if you using session state other then
InProc. If you are using InProc, you can place anything you want into
session.
"Bilbo" <Bilbo@.cox.net> wrote in message
news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I recently read that a class must support serialization in order for it to
> be stored in the Session State. Before reading this I had been storing a
> class to the Session State no problem (without serialization). The class
is
> simply a storage class and contains only primitive types...is it
necessary
> to serialize this object? If so, how do you go about serializing an entire
> class?
> Thanks much.
>
"Bilbo" <Bilbo@.cox.net> wrote in news:eZDMiA1aEHA.2516
@.TK2MSFTNGP10.phx.gbl:

> is it necessary
> to serialize this object?
I think only if you're using session variables in a webfarm:
http://support.microsoft.com/defaul...b;EN-US;q312112
I never had problems storing complex objects in a sesion variable on a
single web server environment.
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]
Check in your Web.config, that's where it is set. InProc is the default.
And if you haven't had any serialization warnings after putting custom
objects into session, then you're using InProc.
"Bilbo" <Bilbo@.cox.net> wrote in message
news:e$8bUo1aEHA.596@.TK2MSFTNGP11.phx.gbl...
> Thanks for your response. How can I tell if I am using InProc?
> Thanks.
>
> "Marina" <someone@.nospam.com> wrote in message
> news:O3%23RuF1aEHA.3820@.tk2msftngp13.phx.gbl...
it
> to
a
class
> entire
>
Thanks for your response. How can I tell if I am using InProc?
Thanks.
"Marina" <someone@.nospam.com> wrote in message
news:O3%23RuF1aEHA.3820@.tk2msftngp13.phx.gbl...
> It only needs to be serializable if you using session state other then
> InProc. If you are using InProc, you can place anything you want into
> session.
> "Bilbo" <Bilbo@.cox.net> wrote in message
> news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
to
> is
> necessary
entire
>

Saturday, March 24, 2012

serialization and Session Object

Hello,

I recently read that a class must support serialization in order for it to
be stored in the Session State. Before reading this I had been storing a
class to the Session State no problem (without serialization). The class is
simply a storage class and contains only primitive types...is it necessary
to serialize this object? If so, how do you go about serializing an entire
class?

Thanks much.BTW, using C#. Thanks

"Bilbo" <Bilbo@.cox.net> wrote in message
news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I recently read that a class must support serialization in order for it to
> be stored in the Session State. Before reading this I had been storing a
> class to the Session State no problem (without serialization). The class
is
> simply a storage class and contains only primitive types...is it
necessary
> to serialize this object? If so, how do you go about serializing an entire
> class?
> Thanks much.
"Bilbo" <Bilbo@.cox.net> wrote in news:eZDMiA1aEHA.2516
@.TK2MSFTNGP10.phx.gbl:

> is it necessary
> to serialize this object?

I think only if you're using session variables in a webfarm:

http://support.microsoft.com/defaul...b;EN-US;q312112

I never had problems storing complex objects in a sesion variable on a
single web server environment.

--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
It only needs to be serializable if you using session state other then
InProc. If you are using InProc, you can place anything you want into
session.

"Bilbo" <Bilbo@.cox.net> wrote in message
news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> Hello,
> I recently read that a class must support serialization in order for it to
> be stored in the Session State. Before reading this I had been storing a
> class to the Session State no problem (without serialization). The class
is
> simply a storage class and contains only primitive types...is it
necessary
> to serialize this object? If so, how do you go about serializing an entire
> class?
> Thanks much.
Thanks for your response. How can I tell if I am using InProc?

Thanks.

"Marina" <someone@.nospam.com> wrote in message
news:O3%23RuF1aEHA.3820@.tk2msftngp13.phx.gbl...
> It only needs to be serializable if you using session state other then
> InProc. If you are using InProc, you can place anything you want into
> session.
> "Bilbo" <Bilbo@.cox.net> wrote in message
> news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> > Hello,
> > I recently read that a class must support serialization in order for it
to
> > be stored in the Session State. Before reading this I had been storing a
> > class to the Session State no problem (without serialization). The class
> is
> > simply a storage class and contains only primitive types...is it
> necessary
> > to serialize this object? If so, how do you go about serializing an
entire
> > class?
> > Thanks much.
Check in your Web.config, that's where it is set. InProc is the default.

And if you haven't had any serialization warnings after putting custom
objects into session, then you're using InProc.

"Bilbo" <Bilbo@.cox.net> wrote in message
news:e$8bUo1aEHA.596@.TK2MSFTNGP11.phx.gbl...
> Thanks for your response. How can I tell if I am using InProc?
> Thanks.
>
> "Marina" <someone@.nospam.com> wrote in message
> news:O3%23RuF1aEHA.3820@.tk2msftngp13.phx.gbl...
> > It only needs to be serializable if you using session state other then
> > InProc. If you are using InProc, you can place anything you want into
> > session.
> > "Bilbo" <Bilbo@.cox.net> wrote in message
> > news:eZDMiA1aEHA.2516@.TK2MSFTNGP10.phx.gbl...
> > > Hello,
> > > > I recently read that a class must support serialization in order for
it
> to
> > > be stored in the Session State. Before reading this I had been storing
a
> > > class to the Session State no problem (without serialization). The
class
> > is
> > > simply a storage class and contains only primitive types...is it
> > necessary
> > > to serialize this object? If so, how do you go about serializing an
> entire
> > > class?
> > > > Thanks much.
> >

Serialization in ASP.NET

Is there any use Serialization in ASP.NET Application ?If Yes then give how to use & some websites for it

check out below articles with example

XML Serialization in ASP.NET, Part 1

XML Serialization in ASP.NET, Part 2

Good Luck./.

Serialization in asp.net

Dear All,
I am bit . Please help.
I created a class and tried to save in ViewState, I got an error asking to
mark class with searizable attribute. But I was able to save that class in
Application and Session without marking.
How this Serialization workes and for which type of .NET framework classes?
Thanks,Basically serialization means the class has the ablility to convert =
itself into a string of characters, and also be able to take this string =
of characters and make a new instance of itself. For your own class, =
you would have to create these methods in order to save it to the =
viewstate (viewstate is essentially, a string of characters!)
This certainly can get quite tricky, so unless you really want to =
persist this class in the viewstate, I'd just use the session.
"asp.net User" <asp.net User@.discussions.microsoft.com> wrote in message =
news:0F2DDEB3-1912-4C44-B884-85D629138106@.microsoft.com...
>=20
> Dear All,
>=20
> I am bit . Please help.
>=20
> I created a class and tried to save in ViewState, I got an error =
asking to=20
> mark class with searizable attribute. But I was able to save that =
class in =20
> Application and Session without marking.
>=20
> How this Serialization workes and for which type of .NET framework =
classes?
>=20
> Thanks,
>=20
>=20
>=20
>=20
>
When you store your object in the Session or the Application I'm guessing
that you're storing a reference to your existing in-memory object. Although
if you're using a sessionState mode were StateServer or SQLServer this
certainly would not be the case.
When you store your object in the ViewState, your object makes a trip to the
client in a hidden field and thus needs to be serializable.
"asp.net User" wrote:

> Dear All,
> I am bit . Please help.
> I created a class and tried to save in ViewState, I got an error asking to
> mark class with searizable attribute. But I was able to save that class in
> Application and Session without marking.
> How this Serialization workes and for which type of .NET framework classes
?
> Thanks,
>
>
>
Thanks Raterus,
I would like to know why Serialization attribute is not requaired in case of
Session and Application.
Thanks Brad ,
I am using "InProc" sessionState.

>I'm guessing
> that you're storing a reference to your existing in-memory object.
Hmm.. not getting this point.
I *think* even in this case(Session and Application) automatic
XMLSerialization of object happens and that Serialized object would be
stored.
Is this correct?
"Brad Quinn" wrote:
> When you store your object in the Session or the Application I'm guessing
> that you're storing a reference to your existing in-memory object. Althou
gh
> if you're using a sessionState mode were StateServer or SQLServer this
> certainly would not be the case.
> When you store your object in the ViewState, your object makes a trip to t
he
> client in a hidden field and thus needs to be serializable.
> "asp.net User" wrote:
>
It's really not tricky at all. To make your class serializable you add an
attribute.
[Serializable]
public class MyClass
{
}
To store an instance of MyClass in the ViewState you do something like this;
MyClass someInstance = MethodReturningMyClass();
ViewState["originalValue"] = someInstance;
And to get it out again;
MyClass originalInstance = (MyClass)ViewState["originalValue"];
"Raterus" wrote:

> Basically serialization means the class has the ablility to convert itself into a
string of characters, and also be able to take this string of characters and make a
new instance of itself. For your own class, you would have to create these methods
in
order to save it to the viewstate (viewstate is essentially, a string of characters!)[color
=darkred]
> This certainly can get quite tricky, so unless you really want to persist
this class in the viewstate, I'd just use the session.
> "asp.net User" <asp.net User@.discussions.microsoft.com> wrote in message n
ews:0F2DDEB3-1912-4C44-B884-85D629138106@.microsoft.com...
>[/color]
Application never uses serialization as it just a reference to the object.
InProc sessions also just are a reference and do not use serialization. Any
out of proc session manager will use serialization.
-- bruce (sqlwork.com)
"asp.net User" <aspnetUser@.discussions.microsoft.com> wrote in message
news:C46ECA6E-60D4-48B3-A5CC-53B8FB4929E6@.microsoft.com...
> Thanks Brad ,
> I am using "InProc" sessionState.
>
> Hmm.. not getting this point.
> I *think* even in this case(Session and Application) automatic
> XMLSerialization of object happens and that Serialized object would be
> stored.
> Is this correct?
>
>
> "Brad Quinn" wrote:
>
guessing
Although
the
asking to
class in
classes?

Serialization of DataView

Hi

What is the best way to serialize Dataview object?
Where we can find the best implementation for the same

ThankI'm not sure that you can serialize a DataView. You can serialize a
DataSet.

"Shyam Remella" <murthy_rs@.sify.com> wrote in message
news:F082AD1B-512D-4E78-90CB-3F317A46DB80@.microsoft.com...
> Hi,
> What is the best way to serialize Dataview object?
> Where we can find the best implementation for the same?
> Thanks

Serialization of Session objects

Hello,
I have implemented SQL Server session state in my application however I am
having some problems. Simple objects stored in Session state are fine and ar
e
handled by .NET, however when I try to store more complex objects such as an
ArrayList in session state I am not able to figure out exactly what I have t
o
do to serialize and deserialize the object.
There doesn't seem to be any code examples around when it comes to
serializing session objects. Could anyone provide me with some code that
would help?
I have managed to successfully serialize and deserialize an object to a file
but I am specifically looking to serialize the object to session state.
Thanks,
GaryAny class stored in session must implement the ISerializable attribute.
http://msdn.microsoft.com/library/d.../>
asstopic.asp
Robbe Morris - 2004/2005 Microsoft MVP C#
Earn money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp
"Gary" <Gary@.discussions.microsoft.com> wrote in message
news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> Hello,
> I have implemented SQL Server session state in my application however I am
> having some problems. Simple objects stored in Session state are fine and
> are
> handled by .NET, however when I try to store more complex objects such as
> an
> ArrayList in session state I am not able to figure out exactly what I have
> to
> do to serialize and deserialize the object.
> There doesn't seem to be any code examples around when it comes to
> serializing session objects. Could anyone provide me with some code that
> would help?
> I have managed to successfully serialize and deserialize an object to a
> file
> but I am specifically looking to serialize the object to session state.
> Thanks,
> Gary
Gary,
All you have to do is to put a line
[Serializable]
before definition of every class you are going to save in the session state.
Eliyahu
"Gary" <Gary@.discussions.microsoft.com> wrote in message
news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> Hello,
> I have implemented SQL Server session state in my application however I am
> having some problems. Simple objects stored in Session state are fine and
are
> handled by .NET, however when I try to store more complex objects such as
an
> ArrayList in session state I am not able to figure out exactly what I have
to
> do to serialize and deserialize the object.
> There doesn't seem to be any code examples around when it comes to
> serializing session objects. Could anyone provide me with some code that
> would help?
> I have managed to successfully serialize and deserialize an object to a
file
> but I am specifically looking to serialize the object to session state.
> Thanks,
> Gary
Hello,
Thank you very much for your reply, adding the <Serializable()> attribute to
my class has resolved my problem. I actually thought that you had to manuall
y
serialize the object and then put it in to the session object, I had no idea
that .NET handles this for you as long as the serialization attribute is
added. I have spent the best part of my day trying to figure this out so
thanks very much!
Regards,
Gary
"Eliyahu Goldin" wrote:

> Gary,
> All you have to do is to put a line
> [Serializable]
> before definition of every class you are going to save in the session stat
e.
>
> Eliyahu
> "Gary" <Gary@.discussions.microsoft.com> wrote in message
> news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> are
> an
> to
> file
>
>
Hello,
Thank you very much for your reply, adding the <Serializable()> attribute to
my class has resolved my problem. I actually thought that you had to manuall
y
serialize the object and then put it in to the session object, I had no idea
that .NET handles this for you as long as the serialization attribute is
added. I have spent the best part of my day trying to figure this out so
thanks very much!
Regards,
Gary
"Robbe Morris [C# MVP]" wrote:

> Any class stored in session must implement the ISerializable attribute.
> http://msdn.microsoft.com/library/d...
classtopic.asp
> --
> Robbe Morris - 2004/2005 Microsoft MVP C#
> Earn money answering .NET Framework
> messageboard posts at EggHeadCafe.com.
> http://www.eggheadcafe.com/forums/merit.asp
>
> "Gary" <Gary@.discussions.microsoft.com> wrote in message
> news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
>
>

Serialization of Session objects

Hello,

I have implemented SQL Server session state in my application however I am
having some problems. Simple objects stored in Session state are fine and are
handled by .NET, however when I try to store more complex objects such as an
ArrayList in session state I am not able to figure out exactly what I have to
do to serialize and deserialize the object.

There doesn't seem to be any code examples around when it comes to
serializing session objects. Could anyone provide me with some code that
would help?

I have managed to successfully serialize and deserialize an object to a file
but I am specifically looking to serialize the object to session state.

Thanks,

GaryAny class stored in session must implement the ISerializable attribute.

http://msdn.microsoft.com/library/d...lasst opic.asp

--
Robbe Morris - 2004/2005 Microsoft MVP C#

Earn money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"Gary" <Gary@.discussions.microsoft.com> wrote in message
news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> Hello,
> I have implemented SQL Server session state in my application however I am
> having some problems. Simple objects stored in Session state are fine and
> are
> handled by .NET, however when I try to store more complex objects such as
> an
> ArrayList in session state I am not able to figure out exactly what I have
> to
> do to serialize and deserialize the object.
> There doesn't seem to be any code examples around when it comes to
> serializing session objects. Could anyone provide me with some code that
> would help?
> I have managed to successfully serialize and deserialize an object to a
> file
> but I am specifically looking to serialize the object to session state.
> Thanks,
> Gary
Gary,

All you have to do is to put a line
[Serializable]

before definition of every class you are going to save in the session state.

Eliyahu

"Gary" <Gary@.discussions.microsoft.com> wrote in message
news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> Hello,
> I have implemented SQL Server session state in my application however I am
> having some problems. Simple objects stored in Session state are fine and
are
> handled by .NET, however when I try to store more complex objects such as
an
> ArrayList in session state I am not able to figure out exactly what I have
to
> do to serialize and deserialize the object.
> There doesn't seem to be any code examples around when it comes to
> serializing session objects. Could anyone provide me with some code that
> would help?
> I have managed to successfully serialize and deserialize an object to a
file
> but I am specifically looking to serialize the object to session state.
> Thanks,
> Gary
Hello,

Thank you very much for your reply, adding the <Serializable()> attribute to
my class has resolved my problem. I actually thought that you had to manually
serialize the object and then put it in to the session object, I had no idea
that .NET handles this for you as long as the serialization attribute is
added. I have spent the best part of my day trying to figure this out so
thanks very much!

Regards,

Gary

"Eliyahu Goldin" wrote:

> Gary,
> All you have to do is to put a line
> [Serializable]
> before definition of every class you are going to save in the session state.
>
> Eliyahu
> "Gary" <Gary@.discussions.microsoft.com> wrote in message
> news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> > Hello,
> > I have implemented SQL Server session state in my application however I am
> > having some problems. Simple objects stored in Session state are fine and
> are
> > handled by .NET, however when I try to store more complex objects such as
> an
> > ArrayList in session state I am not able to figure out exactly what I have
> to
> > do to serialize and deserialize the object.
> > There doesn't seem to be any code examples around when it comes to
> > serializing session objects. Could anyone provide me with some code that
> > would help?
> > I have managed to successfully serialize and deserialize an object to a
> file
> > but I am specifically looking to serialize the object to session state.
> > Thanks,
> > Gary
>
Hello,

Thank you very much for your reply, adding the <Serializable()> attribute to
my class has resolved my problem. I actually thought that you had to manually
serialize the object and then put it in to the session object, I had no idea
that .NET handles this for you as long as the serialization attribute is
added. I have spent the best part of my day trying to figure this out so
thanks very much!

Regards,

Gary

"Robbe Morris [C# MVP]" wrote:

> Any class stored in session must implement the ISerializable attribute.
> http://msdn.microsoft.com/library/d...lasst opic.asp
> --
> Robbe Morris - 2004/2005 Microsoft MVP C#
> Earn money answering .NET Framework
> messageboard posts at EggHeadCafe.com.
> http://www.eggheadcafe.com/forums/merit.asp
>
> "Gary" <Gary@.discussions.microsoft.com> wrote in message
> news:1D664DFE-09DE-46BC-8703-46E108DCCA2B@.microsoft.com...
> > Hello,
> > I have implemented SQL Server session state in my application however I am
> > having some problems. Simple objects stored in Session state are fine and
> > are
> > handled by .NET, however when I try to store more complex objects such as
> > an
> > ArrayList in session state I am not able to figure out exactly what I have
> > to
> > do to serialize and deserialize the object.
> > There doesn't seem to be any code examples around when it comes to
> > serializing session objects. Could anyone provide me with some code that
> > would help?
> > I have managed to successfully serialize and deserialize an object to a
> > file
> > but I am specifically looking to serialize the object to session state.
> > Thanks,
> > Gary
>

Serialization Question

Hi,
I have a collection class called Printers that implement the ICollection and
IEnumerable. This class contains a private ArrayList that holds the Printer
objects. The printer class is a serializable class that contains only the
public name attribute.
After serialization, I want to get the following xml structure;
<Printers>
<Printer>
<Name></Name>
</Printer>
<Printers>
When I want to serialize this Printers collection, I get instead something
like;
<ArrayOfPrinter>
<Printer>
<Name></Name>
</Printer>
</ArrayOfPrinter>
If I take out the ICollection and IEnumerable away, (turning the class into
a normal one) and make the ArrayList public, then I get the following;
<Printers>
<NameOfMyArrayList>
<Printer>
<Name></Name>
</Printer>
</NameOfMyArrayList>
</Printers>
For clarity, I don't include any code at the moment.
Any help appreciated,
EthemHello Ethem,
I'm assuming you mean XmlSerialization... Given that, either the XmlRoot
(if its the top level node) or XmlElement attributes will work.
[XmlRoot("Printers")]
public class PrinterCollection
{
// rest of your code
}
Matt Berther
http://www.mattberther.com

> Hi,
> I have a collection class called Printers that implement the
> ICollection and IEnumerable. This class contains a private ArrayList
> that holds the Printer objects. The printer class is a serializable
> class that contains only the public name attribute.
> After serialization, I want to get the following xml structure;
> <Printers>
> <Printer>
> <Name></Name>
> </Printer>
> <Printers>
> When I want to serialize this Printers collection, I get instead
> something like;
> <ArrayOfPrinter>
> <Printer>
> <Name></Name>
> </Printer>
> </ArrayOfPrinter>
> If I take out the ICollection and IEnumerable away, (turning the class
> into a normal one) and make the ArrayList public, then I get the
> following;
> <Printers>
> <NameOfMyArrayList>
> <Printer>
> <Name></Name>
> </Printer>
> </NameOfMyArrayList>
> </Printers>
> For clarity, I don't include any code at the moment.
> Any help appreciated,
> Ethem
>
Hi Matt,
Thanks for the response. Unfortunately, my collection class implements
ICollection and IEnumerable. If the collection implements these interfaces,
you cannot define an XmlRoot attribute (or any other attribute) on the class
level. Same applies if you derive the collection class from the
CollectionBase.
For my problem, I found a workaround in the following site:
http://dotnet.org.za/armand/archive...09/21/4164.aspx
It seems that you can make it programmatically instead of decleratively.
Thanks,
Ethem
"Matt Berther" wrote:

> Hello Ethem,
> I'm assuming you mean XmlSerialization... Given that, either the XmlRoot
> (if its the top level node) or XmlElement attributes will work.
> [XmlRoot("Printers")]
> public class PrinterCollection
> {
> // rest of your code
> }
> --
> Matt Berther
> http://www.mattberther.com
>
>
>