Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast Error when using Trace #15

Open
drcate opened this issue Apr 22, 2015 · 4 comments
Open

Cast Error when using Trace #15

drcate opened this issue Apr 22, 2015 · 4 comments

Comments

@drcate
Copy link

drcate commented Apr 22, 2015

Thanks for a great implementation of a Redis Session provider!

I found a bug when Trace is enabled (have it at the application level). In web.config
<system.web>
<trace enabled="true" requestLimit="90" pageOutput="false" traceMode="SortByTime" localOnly="false" />
</system.web>

Causes this exception
Exception: System.InvalidCastException
Unable to cast object of type 'System.Collections.Generic.KeyValuePair`2[System.String,System.Object]' to type 'System.String'.

at System.Web.TraceContext.EndRequest()
at System.Web.UI.Page.ProcessRequestEndTrace()
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.sobobacasino_default_aspx.ProcessRequest(HttpContext context) in c:\Users\dcate.MARKETMETRIX\AppData\Local\Temp\Temporary ASP.NET Files\root\ec897ff3\55745380\App_Web_qw3cpivu.0.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I can run fine with Trace turned off, but it might be needed from time to time.

Thanks,

  • Darryl
@leewang0
Copy link
Owner

Thanks for bringing this to my attention :)

@Uladzimir-Kavaliuk
Copy link

The cause of this issue is that TraceContext expects that HttpSessionState would enumerate strings as described here:

/// <summary>
/// Returns an enumerator that can be used to read all the session-state variable names in the current session.
/// </summary>
/// 
/// <returns>
/// An <see cref="T:System.Collections.IEnumerator"/> that can iterate through the variable names in the session-state collection.
/// </returns>
public IEnumerator GetEnumerator()
{
  return this._container.GetEnumerator();
}

But RedisSessionStateItemCollection in fact falls back to Dictionary<string, object> implementation of GetEnumerator().

@MaKCbIMKo
Copy link

I've created a pull request which I think should fix this problem.

@Uladzimir-Kavaliuk
Copy link

Hi welegan!
could you please revise the Maksim's fix #18 once again?

The issue might prevent from using this library in production systems because with RedisSessionProvider this https://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.getenumerator(v=vs.110).aspx is never gonna work.
Any access to Page.Session.GetEnumerator() would return enumerator by KeyValuePair, not by string as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants