ThreadAbortException in ASP.NET + SQLite - sqlite

I am facing this problem a while. Sometimes (just sometimes) i am getting ThreadAbortException in Page_PreRender of one my aspx pages.
this is so odd, i get it sometimes in somedays. I am using SQLite with NHibernate in an asp.net website hosting in a shared webhost.
The exception is :
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session)
at NHibernate.Action.EntityUpdateAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
do you have any idea ??

It's possible that your code took too long to execute (because of too much data, or because SQLite is waiting for another thread's lock on the database).
Try increasing httpRuntime's executionTimeout in the web.config.

Related

Thread Abortion in asmx web service

This error was happened on-and-off when executing the asmx service in background schedule job in production server. In my localhost it work fine. I had try to solve this thread abortion issue by adding System.Web.HttpContext.Current.Server.ScriptTimeout to 90 seconds and longer when process the background job but it still persist. The thread abortion sometimes might occur in different stage but mostly occurs in below stack trace.
System.Threading.ThreadAbortException: Thread was being aborted.
at System.Net.UnsafeNclNativeMethods.OSSOCK.recv(IntPtr socketHandle, Byte* pinnedBuffer, Int32 len, SocketFlags socketFlags)
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)
at FirebirdSql.Data.Client.Managed.Version10.XdrStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at FirebirdSql.Data.Client.Managed.Version10.XdrStream.ReadBytes(Int32 count)
at FirebirdSql.Data.Client.Managed.Version10.XdrStream.ReadInt32()
at FirebirdSql.Data.Client.Managed.Version10.XdrStream.ReadNextOperation()
at FirebirdSql.Data.Client.Managed.Version10.XdrStream.ReadOperation()
at FirebirdSql.Data.Client.Managed.Version11.GdsDatabase.ReadOperation()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadSingleResponse()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadResponse()
at FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.ReadGenericResponse()
at FirebirdSql.Data.Client.Managed.Version12.GdsStatement.Execute()
at FirebirdSql.Data.FirebirdClient.FbCommand.ExecuteNonQuery()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session)
at NHibernate.Action.EntityUpdateAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()

Unable to serialize the session state 'System.Web.SessionState.HttpSessionState'

Getting "Unable to serialize the session state" error, where I'm trying to store HttpSessionState object in Session. Below is my code which is causing issue. Since HttpSessionState is not serializable class and trying to put into session.
Public Shared Property CurrentSession As HttpSessionState
Get
Return TryCast(HttpContext.Current.Session("CurrentSessionObject"), HttpSessionState)
End Get
Set(value As HttpSessionState)
HttpContext.Current.Session("CurrentSessionObject") = value
End Set
End Property
Server Error in '/' Application.
Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.
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. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.
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: Type 'System.Web.SessionState.HttpSessionState' in Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.]
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +12672675
System.Runtime.Serialization.<>c__DisplayClass9_0.b__0(MemberHolder _) +42
System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) +73
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +186
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +166
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +187
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +53
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +571
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +137
System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1644
[HttpException (0x80004005): Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.]
System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1733
System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer) +36
System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer) +652
System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item, Stream stream) +246
System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData item, Int32 initialStreamSize, Byte[]& buf, Int32& length, Boolean compressionEnabled) +65
System.Web.SessionState.SqlSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) +138
System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +589
System.Web.SessionState.SessionStateModule.OnEndRequest(Object source, EventArgs eventArgs) +9947060
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +144
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73
You need to mark the type/s your pushing in to SessionState as serializable, with the [Serializable] attribute.

Simple.Data Insert Object - List initializers must contain at least one initializer

When I run the following code :
var db = Database.Open();
var contact = new Contact() {FirstName = "Mark", LastName = "Rendle"} ;
db.Contacts.Insert(contact);
I get an error :
List initializers must contain at least one initializer
Stack Trace :
at System.Linq.Expressions.Expression.ListInit(NewExpression newExpression, IEnumerable1 initializers)
at Simple.Data.Extensions.ObjectEx.MakeToDictionaryFunc(Type type)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at Simple.Data.Extensions.ObjectEx.ObjectToDictionary(Object obj)
at Simple.Data.Commands.InsertCommand.InsertEntity(Object entity, DataStrategy dataStrategy, String tableName, ErrorCallback onError, Boolean resultRequired)
at Simple.Data.Commands.InsertCommand.DoInsert(InvokeMemberBinder binder, Object[] args, DataStrategy dataStrategy, String tableName)
at Simple.Data.Commands.InsertCommand.Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, Object[] args)
at Simple.Data.DynamicTable.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
at Simple.Data.ObjectReference.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
at CallSite.Target(Closure , CallSite , Object , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
at ProjectXBaseDataImporter.DataSaver.PersistContacts(IEnumerable1 contactsx) in c:\Code\XXX\ProjectXBaseDataImporter\ProjectXBaseDataImporter\CSVImporter.cs:line 54
at ProjectXBaseDataImporter.DataImporter.Import[T](String filePath) in c:\Code\XXX\ProjectXBaseDataImporter\ProjectXBaseDataImporter\CSVImporter.cs:line 77
at ProjectXBaseDataImporter.DataImporter_Test.Import() in c:\Code\XXX\ProjectXBaseDataImporter\ProjectXBaseDataImporter\CSVImporter_Test.cs:line 32
Error on my part.
Another Library I am using requires classes to have fields opposed to properties.
I was coding against the fields not properties.

ASP.NET WebService - Entity Framework

I have an ASP.NET webservice that is making use of Entity Framework 4.0.
When I run one of the methods on the WebService locally, it is throwing the following exception:
System.InvalidOperationException: There was an error generating the
XML document. ---> System.InvalidOperationException: To be XML
serializable, types which inherit from IEnumerable must have an
implementation of Add(System.Object) at all levels of their
inheritance hierarchy.
System.Data.Objects.ObjectQuery`1[[testGoogleEarth.Model.Marker,
testGoogleEarth, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]] does not implement Add(System.Object). at
System.Xml.Serialization.TypeScope.GetEnumeratorElementType(Type type,
TypeFlags& flags) at
System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type,
MemberInfo memberInfo, Boolean directReference) at
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo
source, Boolean directReference, Boolean throwOnError) at
System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type
type) at
System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String
name, String ns, Object o, Boolean xsiType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String
n, String ns, Object o, Boolean isNullable, Boolean needType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write7_JsonResult(String
n, String ns, JsonResult o, Boolean isNullable, Boolean needType)
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write9_JsonResult(Object
o) at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter
xmlWriter, Object o, XmlSerializerNamespaces namespaces, String
encodingStyle, String id) --- End of inner exception stack trace
--- at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String
encodingStyle, String id) at
System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
textWriter, Object o, XmlSerializerNamespaces namespaces) at
System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse
response, Stream outputStream, Object returnValue) at
System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[]
returnValues) at
System.Web.Services.Protocols.WebServiceHandler.Invoke()
I am running this sample on a Windows Server 2008. .NET 4.0 installed.
Any idea?
Thanks
There is problem with the XMLSerializer you are using to serialize the WCF request across the wire. Any IEnumerable class in your object graph should have a public add method. See some details here
http://www.hanselman.com/blog/YouMustImplementTheAddSystemObjectMethodOnMyClassBecauseItInheritsFromIEnumerable.aspx

View Objects in Session of a Running ASP.NET Application

I am trying to move my app to out-of-proc session state and can't find which session object is failing to serialize - the YSOD stack trace is unrevealing.
Is it possible to view the objects, or at least the types of objects, currently stored in session state of a running application? Short of attaching a debugger to a running app, and having its source code available, I don't know if this is possible.
I'm using Alachisoft NCache, so here's their stack trace, though it's not helpful:
System.Web.HttpException (0x80004005): Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode. ---> System.Runtime.Serialization.SerializationException: Type 'System.Web.UI.Control' in Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer)
at System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer)
at System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer)
at System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer)
at Alachisoft.NCache.Web.SessionState.SessionSerializationUtil.Serialize(SessionStateStoreData sessionData)
at Alachisoft.NCache.Web.SessionState.NSessionStoreProvider.InsertContents(HttpContext context, SessionStateStoreData data, SessionStateActions flag, Int32 timeout)
at Alachisoft.NCache.Web.SessionState.NSessionStoreProvider.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData items, Object lockID, Boolean newItem
UPDATE
I have the same results using SQL Server session state:
[SerializationException: Type 'System.Web.UI.Control' in Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.]
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +12475327
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +361
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +413
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +556
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +969
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +1016
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +319
System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1559
[HttpException (0x80004005): Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.]
System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +2273923
System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer) +49
System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer) +811
System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item, Stream stream) +342
System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData item, Int32 initialStreamSize, Byte[]& buf, Int32& length, Boolean compressionEnabled) +99
System.Web.SessionState.SqlSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) +3673544
System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +929
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
Actually your exception tells you exactly what it is: You have a UserControl that is being placed into the Session somewhere and it is not marked as serializable.
---> System.Runtime.Serialization.SerializationException: Type 'System.Web.UI.Control' in Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
Update
You can put some code in a page OnLoad (or similar) that simply iterates the session and dumps that out, it's not too difficult:
foreach(var key in Session.Keys)
Response.Write(String.Format("{0}: {1}<br/>", key, Session[key]);
That's not going to identify the exact code/page but it should give you some search criteria.

Resources