Facebook authentication failing sometime with an InvalidOperationException

This happens when I log in to Facebook and then log in again. It fails here:

public static class UserAuthExtensions
{
    public static void PopulateMissing(this IUserAuthDetails instance, IAuthTokens tokens, bool overwriteReserved = false)
    {
        if (instance == null)
            throw new ArgumentNullException("instance");
        ...

        if (tokens.Items != null)
        {
            var items = instance.Items ?? (instance.Items = new Dictionary<string, string>());
            tokens.Items.ForEach((x,y) => items[x] = y); // EXCEPTION!
        }

        PopulateMissingExtended(instance, tokens, overwriteReserved);
    }

This is the error I get:

Response Status

Error Code
    InvalidOperationException
Message
    Collection was modified; enumeration operation may not execute.
Stack Trace
    [Authenticate: 6/9/2016 1:40:05 PM]: [REQUEST: {provider:facebook}] System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext() at DictionaryExtensions.ForEach[TKey,TValue](Dictionary`2 dictionary, Action`2 onEachFn) at ServiceStack.Auth.UserAuthExtensions.PopulateMissing(IUserAuthDetails instance, IAuthTokens tokens, Boolean overwriteReserved) at ServiceStack.Auth.RedisAuthRepository`2.CreateOrMergeAuthSession(IAuthSession authSession, IAuthTokens tokens) at ServiceStack.Auth.AuthProvider.OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary`2 authInfo) at ServiceStack.Auth.FacebookAuthProvider.Authenticate(IServiceBase authService, IAuthSession session, Authenticate request) at ServiceStack.Auth.AuthenticateService.Authenticate(Authenticate request, String provider, IAuthSession session, IAuthProvider oAuthConfig) at ServiceStack.Auth.AuthenticateService.Post(Authenticate request) at lambda_method(Closure , Object , Object ) at ServiceStack.Host.ServiceRunner`1.Execute(IRequest request, Object instance, TRequest requestDto)
Errors

Please let me know ow to fix this… TIA!

Should now be resolved with the latest v4.0.59 that’s on MyGet.

Unfortunately, with 4.0.60:

[Authenticate: 6/15/2016 9:30:00 PM]: [REQUEST: {provider:facebook}] System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary2.Enumerator.MoveNext() at ServiceStack.Auth.UserAuthExtensions.PopulateMissing(IUserAuthDetails instance, IAuthTokens tokens, Boolean overwriteReserved) at ServiceStack.Auth.RedisAuthRepository2.CreateOrMergeAuthSession(IAuthSession authSession, IAuthTokens tokens) at ServiceStack.Auth.AuthProvider.OnAuthenticated(IServiceBase authService, IAuthSession session, IAuthTokens tokens, Dictionary2 authInfo) at ServiceStack.Auth.FacebookAuthProvider.Authenticate(IServiceBase authService, IAuthSession session, Authenticate request) at ServiceStack.Auth.AuthenticateService.Authenticate(Authenticate request, String provider, IAuthSession session, IAuthProvider oAuthConfig) at ServiceStack.Auth.AuthenticateService.Post(Authenticate request) at lambda_method(Closure , Object , Object ) at ServiceStack.Host.ServiceRunner1.Execute(IRequest request, Object instance, TRequest requestDto)

I’m not seeing any issue with the current implementation are you sure you’ve upgraded to v4.0.60 properly?

Oh, this is embarrassing… It seems like my DLLs were not updated. Sorry about the fuzz, it works as it should now! Case closed.

1 Like