Search

Error when enumerating through claims collection by MonkeyTennis

Active

4
0
Sign in
to vote
Type: Bug
ID: 763742
Opened: 9/20/2012 5:27:36 AM
Access Restriction: Public
0
Workaround(s)
2
User(s) can reproduce this bug
Intermittently we see the following error when browsing a website:

Collection was modified; enumeration operation may not execute.
Exception type:
System.InvalidOperationException
StackTrace:
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at Microsoft.IdentityModel.Claims.ClaimCollection.CopyWithSubject(IClaimsIdentity subject)
at Microsoft.IdentityModel.Claims.WindowsClaimsIdentity.Copy()
at Microsoft.IdentityModel.Claims.WindowsClaimsPrincipal..ctor(WindowsClaimsIdentity identity)
at Microsoft.IdentityModel.Claims.ClaimsPrincipal.CreateFromIdentity(IIdentity identity, String windowsIssuerName)
at Microsoft.IdentityModel.Claims.ClaimsPrincipal.CreateFromIdentities(ClaimsIdentityCollection identities, String windowsIssuerName)
at Microsoft.IdentityModel.Web.SessionAuthenticationModule.SetPrincipalFromSessionToken(SessionSecurityToken sessionSecurityToken)
at Microsoft.IdentityModel.Web.SessionAuthenticationModule.AuthenticateSessionSecurityToken(SessionSecurityToken sessionToken, Boolean writeCookie)
at Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Note this error is occurring within Windows Identity Foundation itself, not our custom code. We do have a SessionSecurityTokenReceived event handler which modifies the claims collection and so I suspect that this is happening at the same time as the stack trace above is executing. However, I can't think of a scenario where both might happen at the same time. regardless, WIF should not error in this way.

Would the fix be to use this._claims.ToList() rather than this._claims, in Microsoft.IdentityModel.Claims.ClaimCollection.CopyWithSubject().
Details (expand)

Describe the problem that you're having.

Intermittent error when browsing a website.

What type of impact does this issue have?

Functionality
File Attachments
0 attachments
Sign in to post a comment.
Posted by froodien1 on 9/20/2012 at 2:55 PM
Could you please post your custom SessionSecurityTokenReceived related code. I think you might be running into a race situation, so maybe applying some lock statements is my wild guess at this point. If you share your code it should help a little more.
Sign in to post a workaround.