Annoying issue yesterday. I was meaning to write a dead-simple web application in .NET 4.0 that talks simultaneously to a referenced .NET 3.5 assembly, and uses an in-house .NET 4.0 framework of services (also referenced). The goal was to test the correct operation between these different .NET version assemblies. In most cases, that’s not even a thing to consider, but we wanted to be absolutely sure.
When calling a method of the referenced 3.5 assembly, which acts as a facade between a client and a web service, there is code that uses the HttpContext.Current.Session. I was assuming that with my test client, being a web application, this would be all fine and dandy, but apparently not. The HttpContext Session was null.
The solution ? Adding
<sessionState mode="InProc" />
to the client application’s web.config, in the <system.web> section.
It’s not clear to me what the cause of this is. I strongly doubt it’s default configuration behaviour, and I’m sure it has nothing to do with the code of the referenced assembly. From what I know and have read on the subject, the session would have been instantiated by starting the application…
If you have a clue, be sure to leave it in the comments.