By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,719 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,719 IT Pros & Developers. It's quick & easy.

Problem with a DataRow in Session

P: n/a
Hi,

Database: SQL Server
Session: SQL Server
Language: C#
Application: ASP.Net

I have created a login page which attempts to retrieve the users record
from the database and I store the validated users DataRow into Session
which is in SQLServer. I have listed the error below for you to
review. I
can successfully store a DataRow on other pages. I don't understand
why it will work for one page and not the other.

The Error:

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:

[SerializationException: The type System.Xml.XmlBoundElement in
Assembly System.Data, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 is not marked as serializable.]

System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMembers(RuntimeType
type, Boolean excludeNonSerializable) +868

System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type
type, StreamingContext context) +300

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInfo()
+103

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +362

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Serialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +48

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(WriteObjectInfo
objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +601

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
+738

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream
serializationStream, Object graph, Header[] headers, Boolean fCheck)
+136
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1621

[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) +1710
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

Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET Version:1.1.4322.2032

Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
For objects to be stored in the SqlSever Session State mechanism, they need
to be able to be serialized. This typically means adding the [Serializable]
attribute to the class. It's essentially a permission slip to let the runtime
take all of the object's state and save it elsewhere (like a binary stream,
which might live in a file or in a database). The DataRow is not marked with
that attribute, thus it hasn't granted permission. IIRC, the DataTable and
DataSet are Serialazible, but those are fairly heavy weight objects to shove
into Session in your database. Consider storing your data in a more light-weight
mannger, perhaps as an array or ArrayList.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi,

Database: SQL Server
Session: SQL Server
Language: C#
Application: ASP.Net
I have created a login page which attempts to retrieve the users
record
from the database and I store the validated users DataRow into Session
which is in SQLServer. I have listed the error below for you to
review. I
can successfully store a DataRow on other pages. I don't understand
why it will work for one page and not the other.
The Error:

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:

[SerializationException: The type System.Xml.XmlBoundElement in
Assembly System.Data, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 is not marked as serializable.]

System.Runtime.Serialization.FormatterServices.Int ernalGetSerializable
Members(RuntimeType type, Boolean excludeNonSerializable) +868

System.Runtime.Serialization.FormatterServices.Get SerializableMembers(
Type type, StreamingContext context) +300

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMem
berInfo() +103

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSer
ialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +362
System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Seriali
ze(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +48
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(Writ
eObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo
typeNameInfo) +601

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(
Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
+738
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Seriali
ze(Stream
serializationStream, Object graph, Header[] headers, Boolean fCheck)
+136
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1621
[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) +1710
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+IExecutio
nStep.Execute()
+60
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step,
Boolean&
completedSynchronously) +87
Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET Version:1.1.4322.2032


Nov 19 '05 #2

P: n/a
While the DataRow is marked as serializable, it's Element property isn't.
It might have worked on some pages because this property was null, and not
on login because it isn't. Since Element property is only used internally,
my guess is that the difference between the two is in how it was created.

You could always use the datarow.ItemArray to get an array of objects...or
map the datarow to a custom User class

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"sdettmers" <sd*******@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi,

Database: SQL Server
Session: SQL Server
Language: C#
Application: ASP.Net

I have created a login page which attempts to retrieve the users record
from the database and I store the validated users DataRow into Session
which is in SQLServer. I have listed the error below for you to
review. I
can successfully store a DataRow on other pages. I don't understand
why it will work for one page and not the other.

The Error:

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:

[SerializationException: The type System.Xml.XmlBoundElement in
Assembly System.Data, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 is not marked as serializable.]

System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMembers(RuntimeType
type, Boolean excludeNonSerializable) +868

System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type
type, StreamingContext context) +300

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInfo()
+103

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +362

System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Serialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter) +48

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Write(WriteObjectInfo
objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +601

System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
+738

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Stream
serializationStream, Object graph, Header[] headers, Boolean fCheck)
+136
System.Web.Util.AltSerialization.WriteValueToStrea m(Object value,
BinaryWriter writer) +1621

[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) +1710
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

Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET Version:1.1.4322.2032

Nov 19 '05 #3

P: n/a
Brock

Thanks for the reply, I appreciate the help. I noticed that on the
microsoft web site they show the DataRow as a Serializable class. I
have posted the link below.

http://msdn.microsoft.com/library/de...classtopic.asp

Nov 19 '05 #4

P: n/a
Karl,

I think you are on to something. On the pages where successfully
storing the DataRow I get the object from SQL but on the login page I
create a dummy DataRow incase the user record was not found in the
database. This was to avoid returning null on the call. I will have
to come up with a new way of handling the null return or create DTO
objects to store the data in Session.
Thanks for your help

Nov 19 '05 #5

P: n/a
Interesting. I was looking at the 2.0 docs and had looked at the 2.0 version
of System.Data.dll, where it is not serializable.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Brock

Thanks for the reply, I appreciate the help. I noticed that on the
microsoft web site they show the DataRow as a Serializable class. I
have posted the link below.

http://msdn.microsoft.com/library/de...ry/en-us/cpref
/html/frlrfsystemdatadatarowclasstopic.asp


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.