Monday, April 11, 2016

Custom MySQL session store provider - deserialization issue

Leave a Comment

I have migrated my project from MSSQL to MySQL and one of the feature I have to implement is a possibility to store sessions on db side, hence custom session store provider has to be configured. I used MySQL connector for visual studio to properly setup session provider. Here is a snippet from my web.config:

<connectionStrings> <remove name="LocalMySqlServer" /> <add name="LocalMySqlServer" connectionString="server=<SERVER>;user=<USER>;pwd=<PASSWORD>;port=<PORT>;database=<DBNAME>;AutoEnlist=false;" providerName="MySql.Data.MySqlClient" /> </connectionStrings>   <system.web>  <sessionState mode="Custom" cookieless="false" timeout="20" allowCustomSqlDatabase="true"  regenerateExpiredSessionId="true" customProvider="MySqlSessionStateProvider">   <providers>     <clear/>     <add name="MySqlSessionStateProvider" type="MySql.Web.SessionState.MySqlSessionStateStore, MySql.Web, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" applicationName="/" description="My Local Session State" connectionStringName="LocalMySqlServer" writeExceptionsToEventLog="True" autogenerateschema="True" enableExpireCallback="False" />   </providers> </sessionState> ... </system.web> 

Once I run my application db schema was modified and all required tables were created:

enter image description here

Furthermore, I detected that during execution session table is filling by session info so I it is a good signal that connection works and MySQL custom provider is doing what is supposed to do.

enter image description here

Unfortunately, after some time my application fails due to System.OutOfMemoryException. The stack trace looks like:

enter image description here

My assumption is that there is some problem with session items deserialization. I have a few classes which are stored in a session and all of them are marked by appropriate [Serializable] attribute. Other items has primitive types (bool, int..) So, my question is what else could cause this issue? The problem is that I even can't detect exact place from where this issue is firing. Any suggestion are appreciated.

1 Answers

Answers 1

Can you please recheck that all items inside your classes are public [ private members would not be taken care of during serialization].

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment