facebookxamarin.androidazure-mobile-servicesmobile-centervisual-studio-app-center

How to debug "the given key was not present in the dictionary" when authenticating through webview with Azure and Xamarin


I am trying to get server managed authentication working with Visual Studio Mobile Center. It uses Azure App Service Authentication. I was able to setup my Facebook Developer account to allow login, then configured it on Mobile Center, and when I go to the mobile center link for auth in a web browser, it works great.

I setup the client side of the authentication identically to Adrian Hall's examples in his book: https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter2/social/#adding-authentication-to-a-mobile-client

When the webview pops up for facebook, it lets me enter credentials, but then crashes when I hit the submit button. This is the stack trace from the application output window:

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
[AndroidRuntime]   at System.ThrowHelper.ThrowKeyNotFoundException () [0x00000] in <8c304e4006094a46a7950338a3b3cb5d>:0 
[AndroidRuntime]   at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x00021] in <8c304e4006094a46a7950338a3b3cb5d>:0 
[AndroidRuntime]   at Microsoft.WindowsAzure.MobileServices.MobileServiceUIAuthentication+<>c__DisplayClass2_0.<LoginAsyncOverride>b__1 (System.Object sender, Xamarin.Auth._MobileServices.AuthenticatorCompletedEventArgs e) [0x00030] in <fe9883f628724025a38f5e1946e5b4c5>:0 
[AndroidRuntime]   at (wrapper delegate-invoke) System.EventHandler`1[Xamarin.Auth._MobileServices.AuthenticatorCompletedEventArgs]:invoke_void_object_TEventArgs (object,Xamarin.Auth._MobileServices.AuthenticatorCompletedEventArgs)
[AndroidRuntime]   at Xamarin.Auth._MobileServices.Authenticator+<>c__DisplayClass22_0.<OnSucceeded>b__0 () [0x00021] in <fe9883f628724025a38f5e1946e5b4c5>:0 
[AndroidRuntime]   at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in <a4e9508b230b49a18f145a67e12eb7b8>:0 
[AndroidRuntime]   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <a4e9508b230b49a18f145a67e12eb7b8>:0 
[AndroidRuntime]   at (wrapper dynamic-method) System.Object:23f66101-d05c-44cc-a8fe-d50bbc9e59d1 (intptr,intptr)

Tested on latest Xamarin Studio and Visual Studio 2017, using Xamarin.Forms 2.3.3, latest Xamarin.Auth, and latest Azure MobileServicesClient.

Any suggestions on how to debug this? I have break on all exceptions checked and I get an Unhandled Exception with a message of "The given key was not present in the dictionary.", no inner exception or stack trace, then it crashes.

EDIT: Reproduction: https://github.com/brandonrisell/TapFriends


Solution

    1. Open the Azure Portal
    2. Find the resource group for your Mobile Center backend
    3. Open up the Mobile Apps resource
    4. Select Authentication / Authorization
    5. Check that the Token store is turned on.

    If it isn't, turn it on, save then restart and recheck.

    I think that's the problem. If not, get back to me here and we'll try something else.