The session state Information is invalid and might be corrupted in ASP.Net

asp.net, session-state, session-variables

Solution

Make sure the FileName1 variable is not null before trying to access it via the Session[FileName1] syntax...

Here's a link to someone else that was having the same problem: http://forums.asp.net/t/1069600.aspx

Here's his answer:

In the code, I found the following line:

//some code
Session.Add(sessionVarName, sessionVarValue);
//some other code

Apparently, because of some dirty data, there is a time when sessionVarName is null.

Session.Add will not throw any exception in this case, and if your Session Mode is "InProc", there will be no problem. However, if your Session Mode is "SQLServer", during deserialization of the session store, you will got the exception that I got. So, to filter out dirty data, I modified the code to become:

if (sessionVarName != null)
{
  //somecode
  Session.Add(sessionVarName, sessionVarValue);
  //some other code
}  

Problem

I am using ASP.Net 3.5 with C#,Development ID:Visual Studio 2008. When I am using ``` Session["FileName1"] = "text1.txt" ``` it is working fine, but then I am using ``` number1=17; string FileName1="FileName1" + number1.toString(); ``` then setting with ``` Session[FileName1]="text1.txt"; ``` gives me runtime error The session state information is invalid and might be corrupted at System.Web.SessionState.SessionStateItemCollection.Deserializer(BinaryReader reader) Can anybody solve my problem, when I am using string in the `Session` variable? Remember it works on my development machine (meaning local Visual Studio) but when deployed to the server it gives mentioned error.

Original source