Name session is not declared ...

Problem

You get this error when compiling your application:

Name 'session' is not declared ...

This generally occurs when using session variables in a code customization and your compiler is not able to find the session variable class.

Solution

Specify the full path of the session variable.  If you cannot access the Session class directly, you may need to specify its full path as follows:

In C#, to access a value:

System.Web.HttpContext.Current.Session[“MyVariable”]

(string) System.Web.HttpContext.Current.Session[“MyVariable”]

In C#, to set a value:

System.Web.HttpContext.Current.Session[“MyVariable”] = “NewValue”

In VB.NET, to access a value:

System.Web.HttpContext.Current.Session(“MyVariable”)

System.Web.HttpContext.Current.Session(“MyVariable”).ToString()

In VB.NET, to set a value:

System.Web.HttpContext.Current.Session(“MyVariable”) = “NewValue”

See Also

Part VII:  Troubleshooting Applications

Application Generation and Compilation Error Messages