Monday, March 26, 2012
Serializable Flag on a Class
around in session state, therefore it must be marked [Serializable] 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 these classes have
some sort of negative impact?
My idea to get around this was to make one light-weight class (that had
no supporting classes) and then have some sort of factory populate it,
this would therefore only require us to mark it serializable and it
would be our traveling container.
Your feedback on this would be appreciated.Yes its a bit of a pain to do it that way if you have a large object
structure.
An alternative is to use the ISerializable interface.
Here's more info:
http://msdn.microsoft.com/library/d.../>
asstopic.asp
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"MrFile" <mrfile.email@.gmail.com> wrote in message
news:1150404557.306716.162240@.y41g2000cwy.googlegroups.com...
> My company has developed a backend component which needs to be carried
> around in session state, therefore it must be marked [Serializable] 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 these classes have
> some sort of negative impact?
> My idea to get around this was to make one light-weight class (that had
> no supporting classes) and then have some sort of factory populate it,
> this would therefore only require us to mark it serializable and it
> would be our traveling container.
> Your feedback on this would be appreciated.
>
Serializable Flag on a Class
around in session state, therefore it must be marked [Serializable] 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 these classes have
some sort of negative impact?
My idea to get around this was to make one light-weight class (that had
no supporting classes) and then have some sort of factory populate it,
this would therefore only require us to mark it serializable and it
would be our traveling container.
Your feedback on this would be appreciated.Yes its a bit of a pain to do it that way if you have a large object
structure.
An alternative is to use the ISerializable interface.
Here's more info:
http://msdn.microsoft.com/library/d...lasst opic.asp
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"MrFile" <mrfile.email@.gmail.com> wrote in message
news:1150404557.306716.162240@.y41g2000cwy.googlegr oups.com...
> My company has developed a backend component which needs to be carried
> around in session state, therefore it must be marked [Serializable] 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 these classes have
> some sort of negative impact?
> My idea to get around this was to make one light-weight class (that had
> no supporting classes) and then have some sort of factory populate it,
> this would therefore only require us to mark it serializable and it
> would be our traveling container.
> Your feedback on this would be appreciated.
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 and Session Object
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/
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
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 of Session objects
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
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
>
Serialize session state & OutOfMemoryError?
SQLServer Session state. After running for several hours, I started getting
the following error. When I access each app individually, only one of the
servers seems to return this error when I step through a sequence. I was
told that I'm trying to store an object not marked as Serializable but I've
tested this on a dev machine storing session variables without any problems,
plus it works for several hours before I have issues. I think something else
is the root of this error but I don't know where to look exactly.
Server Error in '/' Application.
------------------------
Unable to serialize the session state. Please note that non-serializable
objects or MarshalByRef objects are not permitted when session state mode is
'StateServer' or 'SQLServer'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.Web.HttpException: Unable to serialize the session
state. Please note that non-serializable objects or MarshalByRef objects are
not permitted when session state mode is 'StateServer' or 'SQLServer'.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[OutOfMemoryException: Exception of type System.OutOfMemoryException was
thrown.]
[HttpException (0x80004005): Unable to serialize the session state. Please
note that non-serializable objects or MarshalByRef objects are not permitted
when session state mode is 'StateServer' or 'SQLServer'.]
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1711
System.Web.SessionState.SessionDictionary.Serializ e(BinaryWriter writer)
+148
System.Web.SessionState.StateClientManager.Seriali ze(SessionStateItem
item, Stream stream) +146
System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.IStateClientManager.Set(String id, SessionStateItem item, Boolean inStorage) +126
System.Web.SessionState.SessionStateModule.OnRelea seState(Object source,
EventArgs eventArgs) +465
System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute() +60
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously) +87many objects are serialiable until an unserialiable property is set, or an
unserialiable object is added.
-- bruce (sqlwork.com)
"Dave" <Dave@.discussions.microsoft.com> wrote in message
news:F64A9CC1-7B9B-411A-A8FB-1B9CF6C0FFEB@.microsoft.com...
>I have an application running on a 3 server webfarm running Windows 2003
>with
> SQLServer Session state. After running for several hours, I started
> getting
> the following error. When I access each app individually, only one of the
> servers seems to return this error when I step through a sequence. I was
> told that I'm trying to store an object not marked as Serializable but
> I've
> tested this on a dev machine storing session variables without any
> problems,
> plus it works for several hours before I have issues. I think something
> else
> is the root of this error but I don't know where to look exactly.
> Server Error in '/' Application.
> ------------------------
> Unable to serialize the session state. Please note that non-serializable
> objects or MarshalByRef objects are not permitted when session state mode
> is
> 'StateServer' or 'SQLServer'.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about
> the error and where it originated in the code.
> Exception Details: System.Web.HttpException: Unable to serialize the
> session
> state. Please note that non-serializable objects or MarshalByRef objects
> are
> not permitted when session state mode is 'StateServer' or 'SQLServer'.
> Source Error:
> An unhandled exception was generated during the execution of the current
> web
> request. Information regarding the origin and location of the exception
> can
> be identified using the exception stack trace below.
> Stack Trace:
>
> [OutOfMemoryException: Exception of type System.OutOfMemoryException was
> thrown.]
> [HttpException (0x80004005): Unable to serialize the session state. Please
> note that non-serializable objects or MarshalByRef objects are not
> permitted
> when session state mode is 'StateServer' or 'SQLServer'.]
> System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
> BinaryWriter writer) +1711
> System.Web.SessionState.SessionDictionary.Serializ e(BinaryWriter writer)
> +148
> System.Web.SessionState.StateClientManager.Seriali ze(SessionStateItem
> item, Stream stream) +146
> System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.IStateClientManager.Set(String
> id, SessionStateItem item, Boolean inStorage) +126
> System.Web.SessionState.SessionStateModule.OnRelea seState(Object source,
> EventArgs eventArgs) +465
> System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
> +60
> System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
> completedSynchronously) +87
Bruce,
Sorry, can you expand on that? If I'm adding a dataset to my session and a
few hours into the day I start to get this error on one of the servers, I'm
not sure how that it explains the problem
Thanks.
"Bruce Barker" wrote:
> many objects are serialiable until an unserialiable property is set, or an
> unserialiable object is added.
>
> -- bruce (sqlwork.com)
>
> "Dave" <Dave@.discussions.microsoft.com> wrote in message
> news:F64A9CC1-7B9B-411A-A8FB-1B9CF6C0FFEB@.microsoft.com...
> >I have an application running on a 3 server webfarm running Windows 2003
> >with
> > SQLServer Session state. After running for several hours, I started
> > getting
> > the following error. When I access each app individually, only one of the
> > servers seems to return this error when I step through a sequence. I was
> > told that I'm trying to store an object not marked as Serializable but
> > I've
> > tested this on a dev machine storing session variables without any
> > problems,
> > plus it works for several hours before I have issues. I think something
> > else
> > is the root of this error but I don't know where to look exactly.
> > Server Error in '/' Application.
> > ------------------------
> > Unable to serialize the session state. Please note that non-serializable
> > objects or MarshalByRef objects are not permitted when session state mode
> > is
> > 'StateServer' or 'SQLServer'.
> > Description: An unhandled exception occurred during the execution of the
> > current web request. Please review the stack trace for more information
> > about
> > the error and where it originated in the code.
> > Exception Details: System.Web.HttpException: Unable to serialize the
> > session
> > state. Please note that non-serializable objects or MarshalByRef objects
> > are
> > not permitted when session state mode is 'StateServer' or 'SQLServer'.
> > Source Error:
> > An unhandled exception was generated during the execution of the current
> > web
> > request. Information regarding the origin and location of the exception
> > can
> > be identified using the exception stack trace below.
> > Stack Trace:
> > [OutOfMemoryException: Exception of type System.OutOfMemoryException was
> > thrown.]
> > [HttpException (0x80004005): Unable to serialize the session state. Please
> > note that non-serializable objects or MarshalByRef objects are not
> > permitted
> > when session state mode is 'StateServer' or 'SQLServer'.]
> > System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
> > BinaryWriter writer) +1711
> > System.Web.SessionState.SessionDictionary.Serializ e(BinaryWriter writer)
> > +148
> > System.Web.SessionState.StateClientManager.Seriali ze(SessionStateItem
> > item, Stream stream) +146
> > System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.IStateClientManager.Set(String
> > id, SessionStateItem item, Boolean inStorage) +126
> > System.Web.SessionState.SessionStateModule.OnRelea seState(Object source,
> > EventArgs eventArgs) +465
> > System.Web.SyncEventExecutionStep.System.Web.HttpA pplication+IExecutionStep.Execute()
> > +60
> > System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
> > completedSynchronously) +87
>
Serialize session state & OutOfMemoryError?
h
SQLServer Session state. After running for several hours, I started getting
the following error. When I access each app individually, only one of the
servers seems to return this error when I step through a sequence. I was
told that I'm trying to store an object not marked as Serializable but I've
tested this on a dev machine storing session variables without any problems,
plus it works for several hours before I have issues. I think something els
e
is the root of this error but I don't know where to look exactly.
Server Error in '/' Application.
----
--
Unable to serialize the session state. Please note that non-serializable
objects or MarshalByRef objects are not permitted when session state mode is
'StateServer' or 'SQLServer'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information abou
t
the error and where it originated in the code.
Exception Details: System.Web.HttpException: Unable to serialize the session
state. Please note that non-serializable objects or MarshalByRef objects are
not permitted when session state mode is 'StateServer' or 'SQLServer'.
Source Error:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[OutOfMemoryException: Exception of type System.OutOfMemoryException was
thrown.]
[HttpException (0x80004005): Unable to serialize the session state. Please
note that non-serializable objects or MarshalByRef objects are not permitted
when session state mode is 'StateServer' or 'SQLServer'.]
System.Web.Util.AltSerialization.WriteValueToStream(Object value,
BinaryWriter writer) +1711
System.Web.SessionState.SessionDictionary.Serialize(BinaryWriter writer)
+148
System.Web.SessionState.StateClientManager.Serialize(SessionStateItem
item, Stream stream) +146
System.Web.SessionState.SqlStateClientManager.System.Web.SessionState.IState
ClientManager.Set(String id, SessionStateItem item, Boolean inStorage) +126
System.Web.SessionState.SessionStateModule.OnReleaseState(Object source,
EventArgs eventArgs) +465
System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.
Execute() +60
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously) +87many objects are serialiable until an unserialiable property is set, or an
unserialiable object is added.
-- bruce (sqlwork.com)
"Dave" <Dave@.discussions.microsoft.com> wrote in message
news:F64A9CC1-7B9B-411A-A8FB-1B9CF6C0FFEB@.microsoft.com...
>I have an application running on a 3 server webfarm running Windows 2003
>with
> SQLServer Session state. After running for several hours, I started
> getting
> the following error. When I access each app individually, only one of the
> servers seems to return this error when I step through a sequence. I was
> told that I'm trying to store an object not marked as Serializable but
> I've
> tested this on a dev machine storing session variables without any
> problems,
> plus it works for several hours before I have issues. I think something
> else
> is the root of this error but I don't know where to look exactly.
> Server Error in '/' Application.
> ----
--
> Unable to serialize the session state. Please note that non-serializable
> objects or MarshalByRef objects are not permitted when session state mode
> is
> 'StateServer' or 'SQLServer'.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about
> the error and where it originated in the code.
> Exception Details: System.Web.HttpException: Unable to serialize the
> session
> state. Please note that non-serializable objects or MarshalByRef objects
> are
> not permitted when session state mode is 'StateServer' or 'SQLServer'.
> Source Error:
> An unhandled exception was generated during the execution of the current
> web
> request. Information regarding the origin and location of the exception
> can
> be identified using the exception stack trace below.
> Stack Trace:
>
> [OutOfMemoryException: Exception of type System.OutOfMemoryException was
> thrown.]
> [HttpException (0x80004005): Unable to serialize the session state. Please
> note that non-serializable objects or MarshalByRef objects are not
> permitted
> when session state mode is 'StateServer' or 'SQLServer'.]
> System.Web.Util.AltSerialization.WriteValueToStream(Object value,
> BinaryWriter writer) +1711
> System.Web.SessionState.SessionDictionary.Serialize(BinaryWriter writer)
> +148
> System.Web.SessionState.StateClientManager.Serialize(SessionStateItem
> item, Stream stream) +146
> System.Web.SessionState.SqlStateClientManager.System.Web.SessionState.ISta
teClientManager.Set(String
> id, SessionStateItem item, Boolean inStorage) +126
> System.Web.SessionState.SessionStateModule.OnReleaseState(Object source,
> EventArgs eventArgs) +465
> System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionSte
p.Execute()
> +60
> System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
> completedSynchronously) +87
>
>
Bruce,
Sorry, can you expand on that? If I'm adding a dataset to my session and a
few hours into the day I start to get this error on one of the servers, I'm
not sure how that it explains the problem
Thanks.
"Bruce Barker" wrote:
> many objects are serialiable until an unserialiable property is set, or an
> unserialiable object is added.
>
> -- bruce (sqlwork.com)
>
> "Dave" <Dave@.discussions.microsoft.com> wrote in message
> news:F64A9CC1-7B9B-411A-A8FB-1B9CF6C0FFEB@.microsoft.com...
>
>
Serializing
I keep trying different ones, but it errors out saying that they are not
serializable. Do I need to write my own or is there one in the Framework
that is serializable?
I've tried NameValueCollection, Dictionairy<string,string>,
StringDictionairy, etc...
What type does everyone else use that can be serialized?Hello INeedADip,
Application is itself a Name Value collection. So you can use the same.
HTH,
r.
> I need to store some sort of Name-Value collection in the Application
> State.
> I keep trying different ones, but it errors out saying that they are
> not serializable. Do I need to write my own or is there one in the
> Framework that is serializable?
> I've tried NameValueCollection, Dictionairy<string,string>,
> StringDictionairy, etc...
> What type does everyone else use that can be serialized?
Serializing
I keep trying different ones, but it errors out saying that they are not
serializable. Do I need to write my own or is there one in the Framework
that is serializable?
I've tried NameValueCollection, Dictionairy<string,string>,
StringDictionairy, etc...
What type does everyone else use that can be serialized?Hello INeedADip,
Application is itself a Name Value collection. So you can use the same.
HTH,
r.
> I need to store some sort of Name-Value collection in the Application
> State.
> I keep trying different ones, but it errors out saying that they are
> not serializable. Do I need to write my own or is there one in the
> Framework that is serializable?
> I've tried NameValueCollection, Dictionairy<string,string>,
> StringDictionairy, etc...
> What type does everyone else use that can be serialized?
>
Serializing an object from HttpApplicationState
I have an object stored in the HttpApplicationState collection of my
site, but i would like to mantain the state of this object even if the
application restart, so in case of any problem or when I change
something in the web.config or add anything to the bin directory, i can
load the last values from somewhere and continue the work.
I'm using serialization to accomplish this, and it works ok. But i'm
serializing the object to a file in the "HttpApplication.EndRequest"
event. The problem is that with this event, it saves the file in the end
of every instance of HttpApplication, which occours almost every second.
I tested locally, and it saves the file everytime i access any page.
I know that the HttpApplicationState is shared among all the instances
of HttpApplication, and I would like to save the file only before
ApplicationState is destroyed, not the application...
There is no event in HttpApplicationState, so is there any way of doing
this?
Thanks in advance.Hi Natan:
One of the safest things you could do is re-save the file anytime the
value changes (if it is not changing too frequently). This would take
care of even catostrophic failures.
There is an Application_End method you can use in the code behind for
Global.asax. This method should fire whenever the application shuts
down or recycles.
Scott
http://www.OdeToCode.com
On Sun, 26 Sep 2004 19:06:03 -0300, Natan <nvivo@.mandic.com.br> wrote:
>Hi!
>I have an object stored in the HttpApplicationState collection of my
>site, but i would like to mantain the state of this object even if the
>application restart, so in case of any problem or when I change
>something in the web.config or add anything to the bin directory, i can
>load the last values from somewhere and continue the work.
>I'm using serialization to accomplish this, and it works ok. But i'm
>serializing the object to a file in the "HttpApplication.EndRequest"
>event. The problem is that with this event, it saves the file in the end
>of every instance of HttpApplication, which occours almost every second.
>I tested locally, and it saves the file everytime i access any page.
>I know that the HttpApplicationState is shared among all the instances
>of HttpApplication, and I would like to save the file only before
>ApplicationState is destroyed, not the application...
>There is no event in HttpApplicationState, so is there any way of doing
>this?
>
>Thanks in advance.
Scott Allen wrote:
> Hi Natan:
> One of the safest things you could do is re-save the file anytime the
> value changes (if it is not changing too frequently). This would take
> care of even catostrophic failures.
That's what i would like to avoid. File writes are too expensive, and
this would be like 3 or 4 per second. although the file size is aprox.
20k, it is still unnecessary.
> There is an Application_End method you can use in the code behind for
> Global.asax. This method should fire whenever the application shuts
> down or recycles.
Application_End is tied to the EndRequest actually, which is not the
Application in IIS itself, but HttpApplication instance. Many instances
are created and destroyed everytime by the server... take a look at the
documentation.
I really would like to save it only when necessary. Maybe i'll need to
implement it in another way...
Hi Natan:
>Application_End is tied to the EndRequest actually, which is not the
>Application in IIS itself, but HttpApplication instance. Many instances
>are created and destroyed everytime by the server... take a look at the
>documentation.
>
Negative: Application_EndRequest fires as the last event in the
pipeline before the request moves to the HttpHandler for the requested
resource. This happens on every request. Furthermore, the
HttpApplication instance is not destroyed, but is kept in a pool to
service another request.
Application_End, like Application_Start, is invoked only once, and
only invoked on a single HttpApplication instance, the first instance
in the pool. It will fire before the application domain unloads,
although there is some evidence that this behavior is not 100.00%
reliable.
I've been through the documentation many times, but even better I have
code that can demonstrate this behavior. You can watch the output
window of the debugger as you make requests to the web app with the
following code in global. Do an IISRESET to watch Application_End
fire.
public Global()
{
InitializeComponent();
id = System.Threading.Interlocked.Increment(ref counter);
}
protected void Application_Start(Object sender, EventArgs e)
{
Debug.WriteLine("Application_Start on ID: " + id.ToString());
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
Debug.WriteLine("Application_EndRequest on ID: " + id.ToString());
}
protected void Application_End(Object sender, EventArgs e)
{
Debug.WriteLine("Application_End on ID: " + id.ToString());
}
static int counter = 0;
int id = 0;
Hope this helps,
Scott
http://www.OdeToCode.com
Scott Allen wrote:
> Negative: Application_EndRequest fires as the last event in the
> pipeline before the request moves to the HttpHandler for the requested
> resource. This happens on every request. Furthermore, the
> HttpApplication instance is not destroyed, but is kept in a pool to
> service another request.
> Application_End, like Application_Start, is invoked only once, and
> only invoked on a single HttpApplication instance, the first instance
> in the pool. It will fire before the application domain unloads,
> although there is some evidence that this behavior is not 100.00%
> reliable.
Hmmm... thanks. The sdk documentation has some wrong links.
Anyway, the problem with Application_End is that the applicationstate
object is already destroyed, so I can't use it...
=/
Hi Scott!
Suddenly I had the brilliant idea of creating a destructor for my object
(duh... why didn't i thought about it before?), and applying a singleton
pattern for it, so there is only one instance of it and when it is
destroyed, no matter where he is, it serializes itself to the file. When
the application restarts it checks for the file and load the state again.
Thanks anyway!
Serializing an object from HttpApplicationState
I have an object stored in the HttpApplicationState collection of my
site, but i would like to mantain the state of this object even if the
application restart, so in case of any problem or when I change
something in the web.config or add anything to the bin directory, i can
load the last values from somewhere and continue the work.
I'm using serialization to accomplish this, and it works ok. But i'm
serializing the object to a file in the "HttpApplication.EndRequest"
event. The problem is that with this event, it saves the file in the end
of every instance of HttpApplication, which occours almost every second.
I tested locally, and it saves the file everytime i access any page.
I know that the HttpApplicationState is shared among all the instances
of HttpApplication, and I would like to save the file only before
ApplicationState is destroyed, not the application...
There is no event in HttpApplicationState, so is there any way of doing
this?
Thanks in advance.Hi Natan:
One of the safest things you could do is re-save the file anytime the
value changes (if it is not changing too frequently). This would take
care of even catostrophic failures.
There is an Application_End method you can use in the code behind for
Global.asax. This method should fire whenever the application shuts
down or recycles.
--
Scott
http://www.OdeToCode.com
On Sun, 26 Sep 2004 19:06:03 -0300, Natan <nvivo@.mandic.com.br> wrote:
>Hi!
>I have an object stored in the HttpApplicationState collection of my
>site, but i would like to mantain the state of this object even if the
>application restart, so in case of any problem or when I change
>something in the web.config or add anything to the bin directory, i can
>load the last values from somewhere and continue the work.
>I'm using serialization to accomplish this, and it works ok. But i'm
>serializing the object to a file in the "HttpApplication.EndRequest"
>event. The problem is that with this event, it saves the file in the end
>of every instance of HttpApplication, which occours almost every second.
>I tested locally, and it saves the file everytime i access any page.
>I know that the HttpApplicationState is shared among all the instances
>of HttpApplication, and I would like to save the file only before
>ApplicationState is destroyed, not the application...
>There is no event in HttpApplicationState, so is there any way of doing
>this?
>
>Thanks in advance.
Scott Allen wrote:
> Hi Natan:
> One of the safest things you could do is re-save the file anytime the
> value changes (if it is not changing too frequently). This would take
> care of even catostrophic failures.
That's what i would like to avoid. File writes are too expensive, and
this would be like 3 or 4 per second. although the file size is aprox.
20k, it is still unnecessary.
> There is an Application_End method you can use in the code behind for
> Global.asax. This method should fire whenever the application shuts
> down or recycles.
Application_End is tied to the EndRequest actually, which is not the
Application in IIS itself, but HttpApplication instance. Many instances
are created and destroyed everytime by the server... take a look at the
documentation.
I really would like to save it only when necessary. Maybe i'll need to
implement it in another way...
Hi Natan:
>Application_End is tied to the EndRequest actually, which is not the
>Application in IIS itself, but HttpApplication instance. Many instances
>are created and destroyed everytime by the server... take a look at the
>documentation.
Negative: Application_EndRequest fires as the last event in the
pipeline before the request moves to the HttpHandler for the requested
resource. This happens on every request. Furthermore, the
HttpApplication instance is not destroyed, but is kept in a pool to
service another request.
Application_End, like Application_Start, is invoked only once, and
only invoked on a single HttpApplication instance, the first instance
in the pool. It will fire before the application domain unloads,
although there is some evidence that this behavior is not 100.00%
reliable.
I've been through the documentation many times, but even better I have
code that can demonstrate this behavior. You can watch the output
window of the debugger as you make requests to the web app with the
following code in global. Do an IISRESET to watch Application_End
fire.
public Global()
{
InitializeComponent();
id = System.Threading.Interlocked.Increment(ref counter);
}
protected void Application_Start(Object sender, EventArgs e)
{
Debug.WriteLine("Application_Start on ID: " + id.ToString());
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
Debug.WriteLine("Application_EndRequest on ID: " + id.ToString());
}
protected void Application_End(Object sender, EventArgs e)
{
Debug.WriteLine("Application_End on ID: " + id.ToString());
}
static int counter = 0;
int id = 0;
Hope this helps,
--
Scott
http://www.OdeToCode.com
Scott Allen wrote:
> Negative: Application_EndRequest fires as the last event in the
> pipeline before the request moves to the HttpHandler for the requested
> resource. This happens on every request. Furthermore, the
> HttpApplication instance is not destroyed, but is kept in a pool to
> service another request.
> Application_End, like Application_Start, is invoked only once, and
> only invoked on a single HttpApplication instance, the first instance
> in the pool. It will fire before the application domain unloads,
> although there is some evidence that this behavior is not 100.00%
> reliable.
Hmmm... thanks. The sdk documentation has some wrong links.
Anyway, the problem with Application_End is that the applicationstate
object is already destroyed, so I can't use it...
=/
Hi Scott!
Suddenly I had the brilliant idea of creating a destructor for my object
(duh... why didn't i thought about it before?), and applying a singleton
pattern for it, so there is only one instance of it and when it is
destroyed, no matter where he is, it serializes itself to the file. When
the application restarts it checks for the file and load the state again.
Thanks anyway!
Serializing an object from a DLL
that I want to store in Session State. I can not mark the class it comes from
as Serializable because it is from a DLL that I do not have the code for.
There must be an easy way to do this I just can't figure it out.
This is the code that Serializes the item that I want to place in a Session.
private string Serialize(SessionStateItemCollection items)
{
MemoryStream ms = new MemoryStream();
BinaryWriter writer = new BinaryWriter(ms);
if (items != null)
items.Serialize(writer);
writer.Close();
return Convert.ToBase64String(ms.ToArray());
}
I'd really appreciate anyone who could help.unless its sealed, make a new object that inherits from it, and enable
serialization.
the underlying object may not really support serialization (use of unmanged
code, active streams / connections, non-serializable objects). in this case
you can write a custom serializier read/write out the properties, and
perform required initialization.
-- bruce (sqlwork.com)
"Harry" wrote:
Quote:
Originally Posted by
I am using SQL to hold session state. My problem is that I have an object
that I want to store in Session State. I can not mark the class it comes from
as Serializable because it is from a DLL that I do not have the code for.
There must be an easy way to do this I just can't figure it out.
>
>
This is the code that Serializes the item that I want to place in a Session.
>
private string Serialize(SessionStateItemCollection items)
{
MemoryStream ms = new MemoryStream();
BinaryWriter writer = new BinaryWriter(ms);
>
if (items != null)
items.Serialize(writer);
>
writer.Close();
>
return Convert.ToBase64String(ms.ToArray());
}
>
I'd really appreciate anyone who could help.
Serializing an object from a DLL
that I want to store in Session State. I can not mark the class it comes fro
m
as Serializable because it is from a DLL that I do not have the code for.
There must be an easy way to do this I just can't figure it out.
This is the code that Serializes the item that I want to place in a Session.
private string Serialize(SessionStateItemCollection items)
{
MemoryStream ms = new MemoryStream();
BinaryWriter writer = new BinaryWriter(ms);
if (items != null)
items.Serialize(writer);
writer.Close();
return Convert.ToBase64String(ms.ToArray());
}
I'd really appreciate anyone who could help.unless its sealed, make a new object that inherits from it, and enable
serialization.
the underlying object may not really support serialization (use of unmanged
code, active streams / connections, non-serializable objects). in this case
you can write a custom serializier read/write out the properties, and
perform required initialization.
-- bruce (sqlwork.com)
"Harry" wrote:
> I am using SQL to hold session state. My problem is that I have an object
> that I want to store in Session State. I can not mark the class it comes f
rom
> as Serializable because it is from a DLL that I do not have the code for.
> There must be an easy way to do this I just can't figure it out.
>
> This is the code that Serializes the item that I want to place in a Sessio
n.
> private string Serialize(SessionStateItemCollection items)
> {
> MemoryStream ms = new MemoryStream();
> BinaryWriter writer = new BinaryWriter(ms);
> if (items != null)
> items.Serialize(writer);
> writer.Close();
> return Convert.ToBase64String(ms.ToArray());
> }
> I'd really appreciate anyone who could help.
Serializing classes derived from dataset
I am trying to store various objects within session. Due
to the site being hosted in a web farm we are going to
have to use either State Server or SQL Server to persist
the data in session. All of the objects are classes which
inherit from a typed dataset.
Looking at MSDN I have found the following two (what I
believe to be) relevent statements (from article Object
Serialization in the .NET Framework):
"Derived classes should call the GetObjectData method on
the base object if the latter implements ISerializable"
and
"When you derive a new class from one that implements
ISerializable, the derived class must implement both the
constructor as well as the GetObjectData method if it has
any variables that need to be serialized."
Since the Dataset implements ISerializable the above
statements indicate that I should override the
GetObjectData method. However if I try and override this
method I get a compile error stating:
"sub 'GetObjectData' cannot be declared 'Overrides'
because it does not override a sub in a base class."
I am also unable to call the method GetObjectData on the
base class as it is not accessible.
The classes which I am trying to persist have their own
properties, some of which are themselves objects which
inherit from datasets.
If I create a test class which inherits from a typed
dataset, and which has two additional properites (named
Property1 and Property2) the following XML is persisted:
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="dsTemp"
targetNamespace="http://tempuri.org/dsTemp.xsd"
xmlns:mstns="http://tempuri.org/dsTemp.xsd"
xmlns="http://tempuri.org/dsTemp.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified"
elementFormDefault="qualified">
<xs:element name="dsTemp" msdata:IsDataSet="true"
msdata:Property1="1" msdata:Property2="Aidan">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="InvoiceHeader">
<xs:complexType>
<xs:sequence>
<xs:element name="InvoiceHeaderID"
msdata:ReadOnly="true" msdata:AutoIncrement="true"
type="xs:int" />
<xs:element name="POHeaderID" type="xs:int"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="dsTempKey1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:InvoiceHeader" />
<xs:field xpath="mstns:InvoiceHeaderID" />
</xs:unique>
</xs:element>
</xs:schema
Note that the properties have been serialized, but have
been serialized as "<xs:element name="dsTemp"
msdata:IsDataSet="true" msdata:Property1="1"
msdata:Property2="Aidan">"
I can find no way in which I can de-serialize these fields.
Can someone please explain how I can have a class which
inherits from a dataset, and which I can then serialize
and de-serialize without losing the properties.
Thanks in advance
AidanNote that the xml which should have been displayed
indicated that the properties were included in a dataset
element as
msdata:Property1="1"
msdata:Property2="Aidan"
>--Original Message--
>Hi,
>I am trying to store various objects within session. Due
>to the site being hosted in a web farm we are going to
>have to use either State Server or SQL Server to persist
>the data in session. All of the objects are classes
which
>inherit from a typed dataset.
>Looking at MSDN I have found the following two (what I
>believe to be) relevent statements (from article Object
>Serialization in the .NET Framework):
>"Derived classes should call the GetObjectData method on
>the base object if the latter implements ISerializable"
>and
>"When you derive a new class from one that implements
>ISerializable, the derived class must implement both the
>constructor as well as the GetObjectData method if it has
>any variables that need to be serialized."
>Since the Dataset implements ISerializable the above
>statements indicate that I should override the
>GetObjectData method. However if I try and override this
>method I get a compile error stating:
>"sub 'GetObjectData' cannot be declared 'Overrides'
>because it does not override a sub in a base class."
>I am also unable to call the method GetObjectData on the
>base class as it is not accessible.
>The classes which I am trying to persist have their own
>properties, some of which are themselves objects which
>inherit from datasets.
>If I create a test class which inherits from a typed
>dataset, and which has two additional properites (named
>Property1 and Property2) the following XML is persisted:
><?xml version="1.0" encoding="utf-16"?>
><xs:schema id="dsTemp"
>targetNamespace="http://tempuri.org/dsTemp.xsd"
>xmlns:mstns="http://tempuri.org/dsTemp.xsd"
>xmlns="http://tempuri.org/dsTemp.xsd"
>xmlns:xs="http://www.w3.org/2001/XMLSchema"
>xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
>attributeFormDefault="qualified"
>elementFormDefault="qualified">
> <xs:element name="dsTemp" msdata:IsDataSet="true"
>msdata:Property1="1" msdata:Property2="Aidan">
> <xs:complexType>
> <xs:choice maxOccurs="unbounded">
> <xs:element name="InvoiceHeader">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="InvoiceHeaderID"
>msdata:ReadOnly="true" msdata:AutoIncrement="true"
>type="xs:int" />
> <xs:element name="POHeaderID" type="xs:int"
>minOccurs="0" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:choice>
> </xs:complexType>
> <xs:unique name="dsTempKey1" msdata:PrimaryKey="true">
> <xs:selector xpath=".//mstns:InvoiceHeader" />
> <xs:field xpath="mstns:InvoiceHeaderID" />
> </xs:unique>
> </xs:element>
></xs:schema>
>Note that the properties have been serialized, but have
>been serialized as "<xs:element name="dsTemp"
>msdata:IsDataSet="true" msdata:Property1="1"
>msdata:Property2="Aidan">"
>I can find no way in which I can de-serialize these
fields.
>Can someone please explain how I can have a class which
>inherits from a dataset, and which I can then serialize
>and de-serialize without losing the properties.
>Thanks in advance
>Aidan
>.
Serializing drop-down list data sources in Session State
I have several drop-down lists on my ASP.NET page. I need to keep data
sources of these lists in Session State.
What would be the most effective method to serialize this kind of data
structures?
Thanks for any hints,
Leszek TaratutaUse DataTable or HashTable, they are serializable.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> Hello,
> I have several drop-down lists on my ASP.NET page. I need to keep data
> sources of these lists in Session State.
> What would be the most effective method to serialize this kind of data
> structures?
> Thanks for any hints,
> Leszek Taratuta
Thanks, but this what I have already tried. The problem is the ListItem
class is not serializable.
I have created my own ListItem-like class (serializable) and copied
drop-down list data sources (using my ListItem class) to ArrayLists. Then I
put the array lists into a hash table with keys as drop-down lists' ids.
This solution does not work. When I try to deserialize such a structure,
..NET gives me an exception that the type version has been changed and it is
not possible to deserialize data. I think the type is too complex for
serialization (custom ListItem-like objects within ArrayLists within a
Hashtable).
Any other suggestions,
Leszek
"Kikoz" <kikoz@.hotmail.com> wrote in message
news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> Use DataTable or HashTable, they are serializable.
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> > Hello,
> > I have several drop-down lists on my ASP.NET page. I need to keep data
> > sources of these lists in Session State.
> > What would be the most effective method to serialize this kind of data
> > structures?
> > Thanks for any hints,
> > Leszek Taratuta
You didn't say you wanted to serialize Controls, you said you wanted to
serialize the DataSource that you're binding to. A ListItem is a UI Control,
and there's no need (or even a good reason) to serialize it. Just store the
DataTable in Session and bind to it.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> Thanks, but this what I have already tried. The problem is the ListItem
> class is not serializable.
> I have created my own ListItem-like class (serializable) and copied
> drop-down list data sources (using my ListItem class) to ArrayLists. Then
I
> put the array lists into a hash table with keys as drop-down lists' ids.
> This solution does not work. When I try to deserialize such a structure,
> .NET gives me an exception that the type version has been changed and it
is
> not possible to deserialize data. I think the type is too complex for
> serialization (custom ListItem-like objects within ArrayLists within a
> Hashtable).
> Any other suggestions,
> Leszek
> "Kikoz" <kikoz@.hotmail.com> wrote in message
> news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > Use DataTable or HashTable, they are serializable.
> > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> > > Hello,
> > > > I have several drop-down lists on my ASP.NET page. I need to keep data
> > > sources of these lists in Session State.
> > > What would be the most effective method to serialize this kind of data
> > > structures?
> > > > Thanks for any hints,
> > > Leszek Taratuta
> >
Live sample:
(If this ddl doesn't depend on specific user, store it in Application or
Cache):
const string SOURCE_NAME = "SourceName";
private DataTable GetThatFreakingSource()
{
if(Application[SOURCE_NAME] == null)
{
DataTable tbl = GetThatTableFromDbOrSomething();
Application[SOURCE_NAME] = tbl;
return tbl;
}
return (DataTable)Application[SOURCE_NAME];
}
private void BindThatDdl()
{
ddl.DataSource = GetThatFreakingSource();
ddl.DataBind();
}
Done. In sort, when you box Application[SOURCE_NAME] to DataTable (last line
in the first method) that's where serilization takes place. Automatically.
Enjoy :)
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:OAlaM5%23yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> Thanks, but this what I have already tried. The problem is the ListItem
> class is not serializable.
> I have created my own ListItem-like class (serializable) and copied
> drop-down list data sources (using my ListItem class) to ArrayLists. Then
> I
> put the array lists into a hash table with keys as drop-down lists' ids.
> This solution does not work. When I try to deserialize such a structure,
> .NET gives me an exception that the type version has been changed and it
> is
> not possible to deserialize data. I think the type is too complex for
> serialization (custom ListItem-like objects within ArrayLists within a
> Hashtable).
> Any other suggestions,
> Leszek
> "Kikoz" <kikoz@.hotmail.com> wrote in message
> news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
>> Use DataTable or HashTable, they are serializable.
>>
>> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
>> news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
>> > Hello,
>>> > I have several drop-down lists on my ASP.NET page. I need to keep data
>> > sources of these lists in Session State.
>> > What would be the most effective method to serialize this kind of data
>> > structures?
>>> > Thanks for any hints,
>> > Leszek Taratuta
>>>>
>>
Thanks. I forgot the ListItems are controls.
The situation is that my data sources are not DataTables. I have ArrayLists
filled with ListItems.
The problem is I cannot serialize this kind of ArrayLists to session state
kept in state server.
Thanks,
Leszek
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> You didn't say you wanted to serialize Controls, you said you wanted to
> serialize the DataSource that you're binding to. A ListItem is a UI
Control,
> and there's no need (or even a good reason) to serialize it. Just store
the
> DataTable in Session and bind to it.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > Thanks, but this what I have already tried. The problem is the ListItem
> > class is not serializable.
> > I have created my own ListItem-like class (serializable) and copied
> > drop-down list data sources (using my ListItem class) to ArrayLists.
Then
> I
> > put the array lists into a hash table with keys as drop-down lists' ids.
> > This solution does not work. When I try to deserialize such a structure,
> > .NET gives me an exception that the type version has been changed and it
> is
> > not possible to deserialize data. I think the type is too complex for
> > serialization (custom ListItem-like objects within ArrayLists within a
> > Hashtable).
> > Any other suggestions,
> > Leszek
> > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > Use DataTable or HashTable, they are serializable.
> > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> > > > Hello,
> > > > > > I have several drop-down lists on my ASP.NET page. I need to keep
data
> > > > sources of these lists in Session State.
> > > > What would be the most effective method to serialize this kind of
data
> > > > structures?
> > > > > > Thanks for any hints,
> > > > Leszek Taratuta
> > > > > >
I think you complicate things for no obvious reason :) I may be totally
wrong, it all depends on particular situation, but this is what it seems
like. Much easier to store data in serializable object like DataTable and
then keep it on server, even if that would require to put your data in such
table first.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
> Thanks. I forgot the ListItems are controls.
> The situation is that my data sources are not DataTables. I have
> ArrayLists
> filled with ListItems.
> The problem is I cannot serialize this kind of ArrayLists to session state
> kept in state server.
> Thanks,
> Leszek
> "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
>> You didn't say you wanted to serialize Controls, you said you wanted to
>> serialize the DataSource that you're binding to. A ListItem is a UI
> Control,
>> and there's no need (or even a good reason) to serialize it. Just store
> the
>> DataTable in Session and bind to it.
>>
>> --
>> HTH,
>> Kevin Spencer
>> .Net Developer
>> Microsoft MVP
>> Neither a follower
>> nor a lender be.
>>
>> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
>> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
>> > Thanks, but this what I have already tried. The problem is the ListItem
>> > class is not serializable.
>>> > I have created my own ListItem-like class (serializable) and copied
>> > drop-down list data sources (using my ListItem class) to ArrayLists.
> Then
>> I
>> > put the array lists into a hash table with keys as drop-down lists'
>> > ids.
>> > This solution does not work. When I try to deserialize such a
>> > structure,
>> > .NET gives me an exception that the type version has been changed and
>> > it
>> is
>> > not possible to deserialize data. I think the type is too complex for
>> > serialization (custom ListItem-like objects within ArrayLists within a
>> > Hashtable).
>>> > Any other suggestions,
>> > Leszek
>>> > "Kikoz" <kikoz@.hotmail.com> wrote in message
>> > news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
>> > > Use DataTable or HashTable, they are serializable.
>> >> > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
>> > > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
>> > > > Hello,
>> > >> > > > I have several drop-down lists on my ASP.NET page. I need to keep
> data
>> > > > sources of these lists in Session State.
>> > > > What would be the most effective method to serialize this kind of
> data
>> > > > structures?
>> > >> > > > Thanks for any hints,
>> > > > Leszek Taratuta
>> > >> > >> >> >>>>
>>
Well, I know it is much easier to store data in serializable object like
DataTable but I work in a team, and what I receive from the data layer is
ArrayList containing ListItems.
For now the only resonable solution is to convert the ArrayLists to
DataTables. It is not efficient though. I thought it would be any other more
appropriate way to store this kind of data. Any kind of serialization from
ArrayLists to strings or so, and then deserialization.
Thanks,
Leszek
"Kikoz" <kikoz@.hotmail.com> wrote in message
news:Obu#I3$yEHA.1292@.TK2MSFTNGP10.phx.gbl...
> I think you complicate things for no obvious reason :) I may be totally
> wrong, it all depends on particular situation, but this is what it seems
> like. Much easier to store data in serializable object like DataTable and
> then keep it on server, even if that would require to put your data in
such
> table first.
>
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
> > Thanks. I forgot the ListItems are controls.
> > The situation is that my data sources are not DataTables. I have
> > ArrayLists
> > filled with ListItems.
> > The problem is I cannot serialize this kind of ArrayLists to session
state
> > kept in state server.
> > Thanks,
> > Leszek
> > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> >> You didn't say you wanted to serialize Controls, you said you wanted to
> >> serialize the DataSource that you're binding to. A ListItem is a UI
> > Control,
> >> and there's no need (or even a good reason) to serialize it. Just store
> > the
> >> DataTable in Session and bind to it.
> >>
> >> --
> >> HTH,
> >> Kevin Spencer
> >> .Net Developer
> >> Microsoft MVP
> >> Neither a follower
> >> nor a lender be.
> >>
> >> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> >> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> >> > Thanks, but this what I have already tried. The problem is the
ListItem
> >> > class is not serializable.
> >> >> > I have created my own ListItem-like class (serializable) and copied
> >> > drop-down list data sources (using my ListItem class) to ArrayLists.
> > Then
> >> I
> >> > put the array lists into a hash table with keys as drop-down lists'
> >> > ids.
> >> > This solution does not work. When I try to deserialize such a
> >> > structure,
> >> > .NET gives me an exception that the type version has been changed and
> >> > it
> >> is
> >> > not possible to deserialize data. I think the type is too complex for
> >> > serialization (custom ListItem-like objects within ArrayLists within
a
> >> > Hashtable).
> >> >> > Any other suggestions,
> >> > Leszek
> >> >> > "Kikoz" <kikoz@.hotmail.com> wrote in message
> >> > news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> >> > > Use DataTable or HashTable, they are serializable.
> >> > >> > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> >> > > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> >> > > > Hello,
> >> > > >> > > > I have several drop-down lists on my ASP.NET page. I need to keep
> > data
> >> > > > sources of these lists in Session State.
> >> > > > What would be the most effective method to serialize this kind of
> > data
> >> > > > structures?
> >> > > >> > > > Thanks for any hints,
> >> > > > Leszek Taratuta
> >> > > >> > > >> > >> > >> >> >>
> >>
Well, Leszek, it seems that the wrong person is asking this question of the
newsgroup. Whoever is sending you ArrayLists of ListItems is the one who
needs the help!
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:#AIc3TAzEHA.1292@.TK2MSFTNGP10.phx.gbl...
> Well, I know it is much easier to store data in serializable object like
> DataTable but I work in a team, and what I receive from the data layer is
> ArrayList containing ListItems.
> For now the only resonable solution is to convert the ArrayLists to
> DataTables. It is not efficient though. I thought it would be any other
more
> appropriate way to store this kind of data. Any kind of serialization from
> ArrayLists to strings or so, and then deserialization.
> Thanks,
> Leszek
> "Kikoz" <kikoz@.hotmail.com> wrote in message
> news:Obu#I3$yEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > I think you complicate things for no obvious reason :) I may be totally
> > wrong, it all depends on particular situation, but this is what it seems
> > like. Much easier to store data in serializable object like DataTable
and
> > then keep it on server, even if that would require to put your data in
> such
> > table first.
> > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
> > > Thanks. I forgot the ListItems are controls.
> > > The situation is that my data sources are not DataTables. I have
> > > ArrayLists
> > > filled with ListItems.
> > > The problem is I cannot serialize this kind of ArrayLists to session
> state
> > > kept in state server.
> > > > Thanks,
> > > Leszek
> > > > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > > news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> > >> You didn't say you wanted to serialize Controls, you said you wanted
to
> > >> serialize the DataSource that you're binding to. A ListItem is a UI
> > > Control,
> > >> and there's no need (or even a good reason) to serialize it. Just
store
> > > the
> > >> DataTable in Session and bind to it.
> > >>
> > >> --
> > >> HTH,
> > >> Kevin Spencer
> > >> .Net Developer
> > >> Microsoft MVP
> > >> Neither a follower
> > >> nor a lender be.
> > >>
> > >> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > >> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > >> > Thanks, but this what I have already tried. The problem is the
> ListItem
> > >> > class is not serializable.
> > >> > >> > I have created my own ListItem-like class (serializable) and copied
> > >> > drop-down list data sources (using my ListItem class) to
ArrayLists.
> > > Then
> > >> I
> > >> > put the array lists into a hash table with keys as drop-down lists'
> > >> > ids.
> > >> > This solution does not work. When I try to deserialize such a
> > >> > structure,
> > >> > .NET gives me an exception that the type version has been changed
and
> > >> > it
> > >> is
> > >> > not possible to deserialize data. I think the type is too complex
for
> > >> > serialization (custom ListItem-like objects within ArrayLists
within
> a
> > >> > Hashtable).
> > >> > >> > Any other suggestions,
> > >> > Leszek
> > >> > >> > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > >> > news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > >> > > Use DataTable or HashTable, they are serializable.
> > >> > > >> > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > >> > > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> > >> > > > Hello,
> > >> > > > >> > > > I have several drop-down lists on my ASP.NET page. I need to
keep
> > > data
> > >> > > > sources of these lists in Session State.
> > >> > > > What would be the most effective method to serialize this kind
of
> > > data
> > >> > > > structures?
> > >> > > > >> > > > Thanks for any hints,
> > >> > > > Leszek Taratuta
> > >> > > > >> > > > >> > > >> > > >> > >> > >>
> > >>
> >
Thank you. I am going to talk with the guy who creates the data layer.
BTW
What could be the best alternative to get drop-down list data sources from
the data layer? DataTables are pretty heavy. Any other possibilities.
Thanks,
Leszek
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:#raiusAzEHA.1452@.TK2MSFTNGP11.phx.gbl...
> Well, Leszek, it seems that the wrong person is asking this question of
the
> newsgroup. Whoever is sending you ArrayLists of ListItems is the one who
> needs the help!
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:#AIc3TAzEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > Well, I know it is much easier to store data in serializable object like
> > DataTable but I work in a team, and what I receive from the data layer
is
> > ArrayList containing ListItems.
> > For now the only resonable solution is to convert the ArrayLists to
> > DataTables. It is not efficient though. I thought it would be any other
> more
> > appropriate way to store this kind of data. Any kind of serialization
from
> > ArrayLists to strings or so, and then deserialization.
> > Thanks,
> > Leszek
> > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > news:Obu#I3$yEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > > I think you complicate things for no obvious reason :) I may be
totally
> > > wrong, it all depends on particular situation, but this is what it
seems
> > > like. Much easier to store data in serializable object like DataTable
> and
> > > then keep it on server, even if that would require to put your data in
> > such
> > > table first.
> > > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
> > > > Thanks. I forgot the ListItems are controls.
> > > > The situation is that my data sources are not DataTables. I have
> > > > ArrayLists
> > > > filled with ListItems.
> > > > The problem is I cannot serialize this kind of ArrayLists to session
> > state
> > > > kept in state server.
> > > > > > Thanks,
> > > > Leszek
> > > > > > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > > > news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> > > >> You didn't say you wanted to serialize Controls, you said you
wanted
> to
> > > >> serialize the DataSource that you're binding to. A ListItem is a UI
> > > > Control,
> > > >> and there's no need (or even a good reason) to serialize it. Just
> store
> > > > the
> > > >> DataTable in Session and bind to it.
> > > >>
> > > >> --
> > > >> HTH,
> > > >> Kevin Spencer
> > > >> .Net Developer
> > > >> Microsoft MVP
> > > >> Neither a follower
> > > >> nor a lender be.
> > > >>
> > > >> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > >> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > >> > Thanks, but this what I have already tried. The problem is the
> > ListItem
> > > >> > class is not serializable.
> > > >> > > >> > I have created my own ListItem-like class (serializable) and
copied
> > > >> > drop-down list data sources (using my ListItem class) to
> ArrayLists.
> > > > Then
> > > >> I
> > > >> > put the array lists into a hash table with keys as drop-down
lists'
> > > >> > ids.
> > > >> > This solution does not work. When I try to deserialize such a
> > > >> > structure,
> > > >> > .NET gives me an exception that the type version has been changed
> and
> > > >> > it
> > > >> is
> > > >> > not possible to deserialize data. I think the type is too complex
> for
> > > >> > serialization (custom ListItem-like objects within ArrayLists
> within
> > a
> > > >> > Hashtable).
> > > >> > > >> > Any other suggestions,
> > > >> > Leszek
> > > >> > > >> > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > > >> > news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > >> > > Use DataTable or HashTable, they are serializable.
> > > >> > > > >> > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > >> > > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> > > >> > > > Hello,
> > > >> > > > > >> > > > I have several drop-down lists on my ASP.NET page. I need to
> keep
> > > > data
> > > >> > > > sources of these lists in Session State.
> > > >> > > > What would be the most effective method to serialize this
kind
> of
> > > > data
> > > >> > > > structures?
> > > >> > > > > >> > > > Thanks for any hints,
> > > >> > > > Leszek Taratuta
> > > >> > > > > >> > > > > >> > > > >> > > > >> > > >> > > >>
> > > >>
> > > > > >
Hi Leszek,
First of all, as was mentioned earlier, ListItems are UI elements. A
well-designed Data Layer should NEVER work with UI elements. Why, even your
business layer shouldn't be working with UI elements. Only data structures
should come from the Data Layer. That would be raw primitve data, such as
integers, dates, and strings, DataSets, DataTables, and DataReaders. Now,
there is some controversy over returning DataReaders, so the next smallest
data structure (other than primitives) would be a DataTable, and it really
has a relatively small footprint. DataReaders are the smallest, but have
some issues, such as necessitating a constant Connection while in use, as
well as being forward-only, read-only, and not being serializable.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:OIzVpPBzEHA.2568@.TK2MSFTNGP11.phx.gbl...
> Thank you. I am going to talk with the guy who creates the data layer.
> BTW
> What could be the best alternative to get drop-down list data sources from
> the data layer? DataTables are pretty heavy. Any other possibilities.
> Thanks,
> Leszek
> "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> news:#raiusAzEHA.1452@.TK2MSFTNGP11.phx.gbl...
> > Well, Leszek, it seems that the wrong person is asking this question of
> the
> > newsgroup. Whoever is sending you ArrayLists of ListItems is the one who
> > needs the help!
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > Neither a follower
> > nor a lender be.
> > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > news:#AIc3TAzEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > > Well, I know it is much easier to store data in serializable object
like
> > > DataTable but I work in a team, and what I receive from the data layer
> is
> > > ArrayList containing ListItems.
> > > For now the only resonable solution is to convert the ArrayLists to
> > > DataTables. It is not efficient though. I thought it would be any
other
> > more
> > > appropriate way to store this kind of data. Any kind of serialization
> from
> > > ArrayLists to strings or so, and then deserialization.
> > > > Thanks,
> > > Leszek
> > > > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > > news:Obu#I3$yEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > > > I think you complicate things for no obvious reason :) I may be
> totally
> > > > wrong, it all depends on particular situation, but this is what it
> seems
> > > > like. Much easier to store data in serializable object like
DataTable
> > and
> > > > then keep it on server, even if that would require to put your data
in
> > > such
> > > > table first.
> > > > > > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
> > > > > Thanks. I forgot the ListItems are controls.
> > > > > The situation is that my data sources are not DataTables. I have
> > > > > ArrayLists
> > > > > filled with ListItems.
> > > > > The problem is I cannot serialize this kind of ArrayLists to
session
> > > state
> > > > > kept in state server.
> > > > > > > > Thanks,
> > > > > Leszek
> > > > > > > > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > > > > news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> > > > >> You didn't say you wanted to serialize Controls, you said you
> wanted
> > to
> > > > >> serialize the DataSource that you're binding to. A ListItem is a
UI
> > > > > Control,
> > > > >> and there's no need (or even a good reason) to serialize it. Just
> > store
> > > > > the
> > > > >> DataTable in Session and bind to it.
> > > > >>
> > > > >> --
> > > > >> HTH,
> > > > >> Kevin Spencer
> > > > >> .Net Developer
> > > > >> Microsoft MVP
> > > > >> Neither a follower
> > > > >> nor a lender be.
> > > > >>
> > > > >> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > >> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > > >> > Thanks, but this what I have already tried. The problem is the
> > > ListItem
> > > > >> > class is not serializable.
> > > > >> > > > >> > I have created my own ListItem-like class (serializable) and
> copied
> > > > >> > drop-down list data sources (using my ListItem class) to
> > ArrayLists.
> > > > > Then
> > > > >> I
> > > > >> > put the array lists into a hash table with keys as drop-down
> lists'
> > > > >> > ids.
> > > > >> > This solution does not work. When I try to deserialize such a
> > > > >> > structure,
> > > > >> > .NET gives me an exception that the type version has been
changed
> > and
> > > > >> > it
> > > > >> is
> > > > >> > not possible to deserialize data. I think the type is too
complex
> > for
> > > > >> > serialization (custom ListItem-like objects within ArrayLists
> > within
> > > a
> > > > >> > Hashtable).
> > > > >> > > > >> > Any other suggestions,
> > > > >> > Leszek
> > > > >> > > > >> > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > > > >> > news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > > >> > > Use DataTable or HashTable, they are serializable.
> > > > >> > > > > >> > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > >> > > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> > > > >> > > > Hello,
> > > > >> > > > > > >> > > > I have several drop-down lists on my ASP.NET page. I need
to
> > keep
> > > > > data
> > > > >> > > > sources of these lists in Session State.
> > > > >> > > > What would be the most effective method to serialize this
> kind
> > of
> > > > > data
> > > > >> > > > structures?
> > > > >> > > > > > >> > > > Thanks for any hints,
> > > > >> > > > Leszek Taratuta
> > > > >> > > > > > >> > > > > > >> > > > > >> > > > > >> > > > >> > > > >>
> > > > >>
> > > > > > > > > > > >
Thanks a lot. It seems DataTable is the best solution.
In the meantime the database guy decided to fill ArrayLists not with
ListItems but with some user defined structures similar to ListItems:
public sealed class ItemData
{
public string name;
public int val;
public ItemData(string name, int val)
{
this.name = name;
this.val = val;
}
}
Now I need to populate drop-down lists manually using code like this:
// list - an ArrayList containing ItemDatas
// ddl - the drop-down list control
for ( int i = 0; i < list.Count; i++ )
{
ddl.Items.Add( new ListItem( ((ItemData) list[i]).Name, ((ItemData)
list[i]).Id.ToString() ) );
}
What do you think about such a solution? Is it any better than passing
DataTable? For sure it is more cumbersome in terms of populating the lists,
but the database guy wants the smallest possible footprint and ItemData
items are light (they are structures). But on the other hand they are
elements of ArrayList that boxes the sturcture elements (that are value
types) to have reference types.
So my question is which option is better DataTable or the custom-defined
ItemData elements contained in an ArrayList?
Thanks,
Leszek
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:urNAYrBzEHA.3408@.tk2msftngp13.phx.gbl...
> Hi Leszek,
> First of all, as was mentioned earlier, ListItems are UI elements. A
> well-designed Data Layer should NEVER work with UI elements. Why, even
your
> business layer shouldn't be working with UI elements. Only data structures
> should come from the Data Layer. That would be raw primitve data, such as
> integers, dates, and strings, DataSets, DataTables, and DataReaders. Now,
> there is some controversy over returning DataReaders, so the next smallest
> data structure (other than primitives) would be a DataTable, and it really
> has a relatively small footprint. DataReaders are the smallest, but have
> some issues, such as necessitating a constant Connection while in use, as
> well as being forward-only, read-only, and not being serializable.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:OIzVpPBzEHA.2568@.TK2MSFTNGP11.phx.gbl...
> > Thank you. I am going to talk with the guy who creates the data layer.
> > BTW
> > What could be the best alternative to get drop-down list data sources
from
> > the data layer? DataTables are pretty heavy. Any other possibilities.
> > Thanks,
> > Leszek
> > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > news:#raiusAzEHA.1452@.TK2MSFTNGP11.phx.gbl...
> > > Well, Leszek, it seems that the wrong person is asking this question
of
> > the
> > > newsgroup. Whoever is sending you ArrayLists of ListItems is the one
who
> > > needs the help!
> > > > --
> > > HTH,
> > > Kevin Spencer
> > > .Net Developer
> > > Microsoft MVP
> > > Neither a follower
> > > nor a lender be.
> > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > news:#AIc3TAzEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > > > Well, I know it is much easier to store data in serializable object
> like
> > > > DataTable but I work in a team, and what I receive from the data
layer
> > is
> > > > ArrayList containing ListItems.
> > > > For now the only resonable solution is to convert the ArrayLists to
> > > > DataTables. It is not efficient though. I thought it would be any
> other
> > > more
> > > > appropriate way to store this kind of data. Any kind of
serialization
> > from
> > > > ArrayLists to strings or so, and then deserialization.
> > > > > > Thanks,
> > > > Leszek
> > > > > > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > > > news:Obu#I3$yEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > > > > I think you complicate things for no obvious reason :) I may be
> > totally
> > > > > wrong, it all depends on particular situation, but this is what it
> > seems
> > > > > like. Much easier to store data in serializable object like
> DataTable
> > > and
> > > > > then keep it on server, even if that would require to put your
data
> in
> > > > such
> > > > > table first.
> > > > > > > > > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
> > > > > > Thanks. I forgot the ListItems are controls.
> > > > > > The situation is that my data sources are not DataTables. I have
> > > > > > ArrayLists
> > > > > > filled with ListItems.
> > > > > > The problem is I cannot serialize this kind of ArrayLists to
> session
> > > > state
> > > > > > kept in state server.
> > > > > > > > > > Thanks,
> > > > > > Leszek
> > > > > > > > > > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > > > > > news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> > > > > >> You didn't say you wanted to serialize Controls, you said you
> > wanted
> > > to
> > > > > >> serialize the DataSource that you're binding to. A ListItem is
a
> UI
> > > > > > Control,
> > > > > >> and there's no need (or even a good reason) to serialize it.
Just
> > > store
> > > > > > the
> > > > > >> DataTable in Session and bind to it.
> > > > > >>
> > > > > >> --
> > > > > >> HTH,
> > > > > >> Kevin Spencer
> > > > > >> .Net Developer
> > > > > >> Microsoft MVP
> > > > > >> Neither a follower
> > > > > >> nor a lender be.
> > > > > >>
> > > > > >> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > >> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > > > >> > Thanks, but this what I have already tried. The problem is
the
> > > > ListItem
> > > > > >> > class is not serializable.
> > > > > >> > > > > >> > I have created my own ListItem-like class (serializable) and
> > copied
> > > > > >> > drop-down list data sources (using my ListItem class) to
> > > ArrayLists.
> > > > > > Then
> > > > > >> I
> > > > > >> > put the array lists into a hash table with keys as drop-down
> > lists'
> > > > > >> > ids.
> > > > > >> > This solution does not work. When I try to deserialize such a
> > > > > >> > structure,
> > > > > >> > .NET gives me an exception that the type version has been
> changed
> > > and
> > > > > >> > it
> > > > > >> is
> > > > > >> > not possible to deserialize data. I think the type is too
> complex
> > > for
> > > > > >> > serialization (custom ListItem-like objects within ArrayLists
> > > within
> > > > a
> > > > > >> > Hashtable).
> > > > > >> > > > > >> > Any other suggestions,
> > > > > >> > Leszek
> > > > > >> > > > > >> > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > > > > >> > news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > > > >> > > Use DataTable or HashTable, they are serializable.
> > > > > >> > > > > > >> > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > >> > > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> > > > > >> > > > Hello,
> > > > > >> > > > > > > >> > > > I have several drop-down lists on my ASP.NET page. I need
> to
> > > keep
> > > > > > data
> > > > > >> > > > sources of these lists in Session State.
> > > > > >> > > > What would be the most effective method to serialize this
> > kind
> > > of
> > > > > > data
> > > > > >> > > > structures?
> > > > > >> > > > > > > >> > > > Thanks for any hints,
> > > > > >> > > > Leszek Taratuta
> > > > > >> > > > > > > >> > > > > > > >> > > > > > >> > > > > > >> > > > > >> > > > > >>
> > > > > >>
> > > > > > > > > > > > > > > > > > > >
I would go with a DataTable.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
"Leszek Taratuta" <ads@.taratuta.net> wrote in message
news:uxFQ8ACzEHA.804@.TK2MSFTNGP12.phx.gbl...
> Thanks a lot. It seems DataTable is the best solution.
> In the meantime the database guy decided to fill ArrayLists not with
> ListItems but with some user defined structures similar to ListItems:
> public sealed class ItemData
> {
> public string name;
> public int val;
> public ItemData(string name, int val)
> {
> this.name = name;
> this.val = val;
> }
> }
> Now I need to populate drop-down lists manually using code like this:
> // list - an ArrayList containing ItemDatas
> // ddl - the drop-down list control
> for ( int i = 0; i < list.Count; i++ )
> {
> ddl.Items.Add( new ListItem( ((ItemData) list[i]).Name, ((ItemData)
> list[i]).Id.ToString() ) );
> }
> What do you think about such a solution? Is it any better than passing
> DataTable? For sure it is more cumbersome in terms of populating the
lists,
> but the database guy wants the smallest possible footprint and ItemData
> items are light (they are structures). But on the other hand they are
> elements of ArrayList that boxes the sturcture elements (that are value
> types) to have reference types.
> So my question is which option is better DataTable or the custom-defined
> ItemData elements contained in an ArrayList?
> Thanks,
> Leszek
> "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> news:urNAYrBzEHA.3408@.tk2msftngp13.phx.gbl...
> > Hi Leszek,
> > First of all, as was mentioned earlier, ListItems are UI elements. A
> > well-designed Data Layer should NEVER work with UI elements. Why, even
> your
> > business layer shouldn't be working with UI elements. Only data
structures
> > should come from the Data Layer. That would be raw primitve data, such
as
> > integers, dates, and strings, DataSets, DataTables, and DataReaders.
Now,
> > there is some controversy over returning DataReaders, so the next
smallest
> > data structure (other than primitives) would be a DataTable, and it
really
> > has a relatively small footprint. DataReaders are the smallest, but have
> > some issues, such as necessitating a constant Connection while in use,
as
> > well as being forward-only, read-only, and not being serializable.
> > --
> > HTH,
> > Kevin Spencer
> > .Net Developer
> > Microsoft MVP
> > Neither a follower
> > nor a lender be.
> > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > news:OIzVpPBzEHA.2568@.TK2MSFTNGP11.phx.gbl...
> > > Thank you. I am going to talk with the guy who creates the data layer.
> > > > BTW
> > > What could be the best alternative to get drop-down list data sources
> from
> > > the data layer? DataTables are pretty heavy. Any other possibilities.
> > > > Thanks,
> > > > Leszek
> > > > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > > news:#raiusAzEHA.1452@.TK2MSFTNGP11.phx.gbl...
> > > > Well, Leszek, it seems that the wrong person is asking this question
> of
> > > the
> > > > newsgroup. Whoever is sending you ArrayLists of ListItems is the one
> who
> > > > needs the help!
> > > > > > --
> > > > HTH,
> > > > Kevin Spencer
> > > > .Net Developer
> > > > Microsoft MVP
> > > > Neither a follower
> > > > nor a lender be.
> > > > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > news:#AIc3TAzEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > > > > Well, I know it is much easier to store data in serializable
object
> > like
> > > > > DataTable but I work in a team, and what I receive from the data
> layer
> > > is
> > > > > ArrayList containing ListItems.
> > > > > For now the only resonable solution is to convert the ArrayLists
to
> > > > > DataTables. It is not efficient though. I thought it would be any
> > other
> > > > more
> > > > > appropriate way to store this kind of data. Any kind of
> serialization
> > > from
> > > > > ArrayLists to strings or so, and then deserialization.
> > > > > > > > Thanks,
> > > > > Leszek
> > > > > > > > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > > > > news:Obu#I3$yEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > > > > > I think you complicate things for no obvious reason :) I may be
> > > totally
> > > > > > wrong, it all depends on particular situation, but this is what
it
> > > seems
> > > > > > like. Much easier to store data in serializable object like
> > DataTable
> > > > and
> > > > > > then keep it on server, even if that would require to put your
> data
> > in
> > > > > such
> > > > > > table first.
> > > > > > > > > > > > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > > news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
> > > > > > > Thanks. I forgot the ListItems are controls.
> > > > > > > The situation is that my data sources are not DataTables. I
have
> > > > > > > ArrayLists
> > > > > > > filled with ListItems.
> > > > > > > The problem is I cannot serialize this kind of ArrayLists to
> > session
> > > > > state
> > > > > > > kept in state server.
> > > > > > > > > > > > Thanks,
> > > > > > > Leszek
> > > > > > > > > > > > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > > > > > > news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> > > > > > >> You didn't say you wanted to serialize Controls, you said you
> > > wanted
> > > > to
> > > > > > >> serialize the DataSource that you're binding to. A ListItem
is
> a
> > UI
> > > > > > > Control,
> > > > > > >> and there's no need (or even a good reason) to serialize it.
> Just
> > > > store
> > > > > > > the
> > > > > > >> DataTable in Session and bind to it.
> > > > > > >>
> > > > > > >> --
> > > > > > >> HTH,
> > > > > > >> Kevin Spencer
> > > > > > >> .Net Developer
> > > > > > >> Microsoft MVP
> > > > > > >> Neither a follower
> > > > > > >> nor a lender be.
> > > > > > >>
> > > > > > >> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > > >> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > > > > >> > Thanks, but this what I have already tried. The problem is
> the
> > > > > ListItem
> > > > > > >> > class is not serializable.
> > > > > > >> > > > > > >> > I have created my own ListItem-like class (serializable)
and
> > > copied
> > > > > > >> > drop-down list data sources (using my ListItem class) to
> > > > ArrayLists.
> > > > > > > Then
> > > > > > >> I
> > > > > > >> > put the array lists into a hash table with keys as
drop-down
> > > lists'
> > > > > > >> > ids.
> > > > > > >> > This solution does not work. When I try to deserialize such
a
> > > > > > >> > structure,
> > > > > > >> > .NET gives me an exception that the type version has been
> > changed
> > > > and
> > > > > > >> > it
> > > > > > >> is
> > > > > > >> > not possible to deserialize data. I think the type is too
> > complex
> > > > for
> > > > > > >> > serialization (custom ListItem-like objects within
ArrayLists
> > > > within
> > > > > a
> > > > > > >> > Hashtable).
> > > > > > >> > > > > > >> > Any other suggestions,
> > > > > > >> > Leszek
> > > > > > >> > > > > > >> > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > > > > > >> > news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > > > > >> > > Use DataTable or HashTable, they are serializable.
> > > > > > >> > > > > > > >> > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > > >> > > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> > > > > > >> > > > Hello,
> > > > > > >> > > > > > > > >> > > > I have several drop-down lists on my ASP.NET page. I
need
> > to
> > > > keep
> > > > > > > data
> > > > > > >> > > > sources of these lists in Session State.
> > > > > > >> > > > What would be the most effective method to serialize
this
> > > kind
> > > > of
> > > > > > > data
> > > > > > >> > > > structures?
> > > > > > >> > > > > > > > >> > > > Thanks for any hints,
> > > > > > >> > > > Leszek Taratuta
> > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > >> > > > > > > >> > > > > > >> > > > > > >>
> > > > > > >>
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Thanks a lot. I will use DataTables.
Leszek
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:#9O8zoCzEHA.1524@.TK2MSFTNGP09.phx.gbl...
> I would go with a DataTable.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> news:uxFQ8ACzEHA.804@.TK2MSFTNGP12.phx.gbl...
> > Thanks a lot. It seems DataTable is the best solution.
> > In the meantime the database guy decided to fill ArrayLists not with
> > ListItems but with some user defined structures similar to ListItems:
> > public sealed class ItemData
> > {
> > public string name;
> > public int val;
> > public ItemData(string name, int val)
> > {
> > this.name = name;
> > this.val = val;
> > }
> > }
> > Now I need to populate drop-down lists manually using code like this:
> > // list - an ArrayList containing ItemDatas
> > // ddl - the drop-down list control
> > for ( int i = 0; i < list.Count; i++ )
> > {
> > ddl.Items.Add( new ListItem( ((ItemData) list[i]).Name, ((ItemData)
> > list[i]).Id.ToString() ) );
> > }
> > What do you think about such a solution? Is it any better than passing
> > DataTable? For sure it is more cumbersome in terms of populating the
> lists,
> > but the database guy wants the smallest possible footprint and ItemData
> > items are light (they are structures). But on the other hand they are
> > elements of ArrayList that boxes the sturcture elements (that are value
> > types) to have reference types.
> > So my question is which option is better DataTable or the custom-defined
> > ItemData elements contained in an ArrayList?
> > Thanks,
> > Leszek
> > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > news:urNAYrBzEHA.3408@.tk2msftngp13.phx.gbl...
> > > Hi Leszek,
> > > > First of all, as was mentioned earlier, ListItems are UI elements. A
> > > well-designed Data Layer should NEVER work with UI elements. Why, even
> > your
> > > business layer shouldn't be working with UI elements. Only data
> structures
> > > should come from the Data Layer. That would be raw primitve data, such
> as
> > > integers, dates, and strings, DataSets, DataTables, and DataReaders.
> Now,
> > > there is some controversy over returning DataReaders, so the next
> smallest
> > > data structure (other than primitives) would be a DataTable, and it
> really
> > > has a relatively small footprint. DataReaders are the smallest, but
have
> > > some issues, such as necessitating a constant Connection while in use,
> as
> > > well as being forward-only, read-only, and not being serializable.
> > > > --
> > > HTH,
> > > Kevin Spencer
> > > .Net Developer
> > > Microsoft MVP
> > > Neither a follower
> > > nor a lender be.
> > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > news:OIzVpPBzEHA.2568@.TK2MSFTNGP11.phx.gbl...
> > > > Thank you. I am going to talk with the guy who creates the data
layer.
> > > > > > BTW
> > > > What could be the best alternative to get drop-down list data
sources
> > from
> > > > the data layer? DataTables are pretty heavy. Any other
possibilities.
> > > > > > Thanks,
> > > > > > Leszek
> > > > > > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > > > news:#raiusAzEHA.1452@.TK2MSFTNGP11.phx.gbl...
> > > > > Well, Leszek, it seems that the wrong person is asking this
question
> > of
> > > > the
> > > > > newsgroup. Whoever is sending you ArrayLists of ListItems is the
one
> > who
> > > > > needs the help!
> > > > > > > > --
> > > > > HTH,
> > > > > Kevin Spencer
> > > > > .Net Developer
> > > > > Microsoft MVP
> > > > > Neither a follower
> > > > > nor a lender be.
> > > > > > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > news:#AIc3TAzEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > > > > > Well, I know it is much easier to store data in serializable
> object
> > > like
> > > > > > DataTable but I work in a team, and what I receive from the data
> > layer
> > > > is
> > > > > > ArrayList containing ListItems.
> > > > > > For now the only resonable solution is to convert the ArrayLists
> to
> > > > > > DataTables. It is not efficient though. I thought it would be
any
> > > other
> > > > > more
> > > > > > appropriate way to store this kind of data. Any kind of
> > serialization
> > > > from
> > > > > > ArrayLists to strings or so, and then deserialization.
> > > > > > > > > > Thanks,
> > > > > > Leszek
> > > > > > > > > > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > > > > > news:Obu#I3$yEHA.1292@.TK2MSFTNGP10.phx.gbl...
> > > > > > > I think you complicate things for no obvious reason :) I may
be
> > > > totally
> > > > > > > wrong, it all depends on particular situation, but this is
what
> it
> > > > seems
> > > > > > > like. Much easier to store data in serializable object like
> > > DataTable
> > > > > and
> > > > > > > then keep it on server, even if that would require to put your
> > data
> > > in
> > > > > > such
> > > > > > > table first.
> > > > > > > > > > > > > > > > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > > > news:OEVLPz$yEHA.1412@.tk2msftngp13.phx.gbl...
> > > > > > > > Thanks. I forgot the ListItems are controls.
> > > > > > > > The situation is that my data sources are not DataTables. I
> have
> > > > > > > > ArrayLists
> > > > > > > > filled with ListItems.
> > > > > > > > The problem is I cannot serialize this kind of ArrayLists to
> > > session
> > > > > > state
> > > > > > > > kept in state server.
> > > > > > > > > > > > > > Thanks,
> > > > > > > > Leszek
> > > > > > > > > > > > > > "Kevin Spencer" <kspencer@.takempis.com> wrote in message
> > > > > > > > news:uC0bhX$yEHA.336@.TK2MSFTNGP10.phx.gbl...
> > > > > > > >> You didn't say you wanted to serialize Controls, you said
you
> > > > wanted
> > > > > to
> > > > > > > >> serialize the DataSource that you're binding to. A ListItem
> is
> > a
> > > UI
> > > > > > > > Control,
> > > > > > > >> and there's no need (or even a good reason) to serialize
it.
> > Just
> > > > > store
> > > > > > > > the
> > > > > > > >> DataTable in Session and bind to it.
> > > > > > > >>
> > > > > > > >> --
> > > > > > > >> HTH,
> > > > > > > >> Kevin Spencer
> > > > > > > >> .Net Developer
> > > > > > > >> Microsoft MVP
> > > > > > > >> Neither a follower
> > > > > > > >> nor a lender be.
> > > > > > > >>
> > > > > > > >> "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > > > >> news:OAlaM5#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > > > > > >> > Thanks, but this what I have already tried. The problem
is
> > the
> > > > > > ListItem
> > > > > > > >> > class is not serializable.
> > > > > > > >> > > > > > > >> > I have created my own ListItem-like class (serializable)
> and
> > > > copied
> > > > > > > >> > drop-down list data sources (using my ListItem class) to
> > > > > ArrayLists.
> > > > > > > > Then
> > > > > > > >> I
> > > > > > > >> > put the array lists into a hash table with keys as
> drop-down
> > > > lists'
> > > > > > > >> > ids.
> > > > > > > >> > This solution does not work. When I try to deserialize
such
> a
> > > > > > > >> > structure,
> > > > > > > >> > .NET gives me an exception that the type version has been
> > > changed
> > > > > and
> > > > > > > >> > it
> > > > > > > >> is
> > > > > > > >> > not possible to deserialize data. I think the type is too
> > > complex
> > > > > for
> > > > > > > >> > serialization (custom ListItem-like objects within
> ArrayLists
> > > > > within
> > > > > > a
> > > > > > > >> > Hashtable).
> > > > > > > >> > > > > > > >> > Any other suggestions,
> > > > > > > >> > Leszek
> > > > > > > >> > > > > > > >> > "Kikoz" <kikoz@.hotmail.com> wrote in message
> > > > > > > >> > news:O14Fov#yEHA.4044@.TK2MSFTNGP10.phx.gbl...
> > > > > > > >> > > Use DataTable or HashTable, they are serializable.
> > > > > > > >> > > > > > > > >> > > "Leszek Taratuta" <ads@.taratuta.net> wrote in message
> > > > > > > >> > > news:%23byMha%23yEHA.2200@.TK2MSFTNGP09.phx.gbl...
> > > > > > > >> > > > Hello,
> > > > > > > >> > > > > > > > > >> > > > I have several drop-down lists on my ASP.NET page. I
> need
> > > to
> > > > > keep
> > > > > > > > data
> > > > > > > >> > > > sources of these lists in Session State.
> > > > > > > >> > > > What would be the most effective method to serialize
> this
> > > > kind
> > > > > of
> > > > > > > > data
> > > > > > > >> > > > structures?
> > > > > > > >> > > > > > > > > >> > > > Thanks for any hints,
> > > > > > > >> > > > Leszek Taratuta
> > > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > > > > > >> > > > > > > > >> > > > > > > >> > > > > > > >>
> > > > > > > >>
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >