When hooking up an ASP.NET website to Azure Redis Cache (but this error also occurs when using a local redis instance) using the Microsoft ASP.NET Redis Session State provider, I get a Null Reference Exception. Why? Google tells me nothing. I have tried using the Russian Redis Session State provider, but that randomly corrupts the session state, so I can't use that either.
This is the stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.Web.Redis.StackExchangeClientConnection.Eval(String script, String[] keyArgs, Object[] valueArgs) +381
Microsoft.Web.Redis.RedisConnectionWrapper.TryUpdateIfLockIdMatch(Object lockId, ISessionStateItemCollection data, Int32 sessionTimeout) +108
Microsoft.Web.Redis.RedisSessionStateProvider.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) +1280
System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +565
System.Web.SessionState.SessionStateModule.OnEndRequest(Object source, EventArgs eventArgs) +139
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
I have no idea where this problem occurs as the stack trace doesn't touch my code, but it occurs on any url hitting my site after I am logged in, yes using forms authentication.
My redis config looks like this:
<sessionState mode="Custom" customProvider="RedisSessionStateStoreProvider">
<providers>
<clear />
<add name="RedisSessionStateStoreProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider, Microsoft.Web.RedisSessionStateProvider, Version=0.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
host="*******.redis.cache.windows.net"
throwOnError = "true"
connectionTimeoutInMilliseconds = "5000"
retryTimeoutInMilliseconds = "5000"
operationTimeoutInMilliseconds = "5000"
ssl="true"
accessKey="*******************************"
/>
</providers>
... where I have starred out the access key and service uri.
EDIT: I was happy, and thought I had found the solution when I found a post on MSDN Forums (booh!) that dealt with intermittent null reference exceptions where they warned that a nonexistent key being assigned with with a null value will break everything. I found an instance where I was doing this and fixed it,but that didn't actually do the trick and the same problem remains.
I am using Microsoft.Web.RedisSessionStateProvider 0.4.0.0-Pre-121 that allegedly fixes a similar bug