Microsoft-authentication-library-for-dotnet: Object reference not set to an instance of an object

Created on 31 May 2018  Â·  8Comments  Â·  Source: AzureAD/microsoft-authentication-library-for-dotnet

Hi,

I'm using Microsoft.Identity.Client, Version=1.1.3.-preview0012

And i've got this error on iOS. (android works fine)

{System.NullReferenceException: Object reference not set to an instance of an object
at Microsoft.Identity.Client.TokenCacheAccessor.Remove (System.String key, System.String service) [0x00055] in <7f73819fd99b45669100adda813d89e4>:0
at Microsoft.Identity.Client.TokenCacheAccessor.SetValueForKey (System.String key, System.String value, System.String service) [0x00000] in <7f73819fd99b45669100adda813d89e4>:0
at Microsoft.Identity.Client.TokenCacheAccessor.SaveAccessToken (System.String cacheKey, System.String item) [0x00000] in <7f73819fd99b45669100adda813d89e4>:0
at Microsoft.Identity.Client.Internal.Telemetry.TelemetryTokenCacheAccessor.SaveAccessToken (System.String cacheKey, System.String item, Microsoft.Identity.Client.Internal.RequestContext requestContext) [0x00023] in <7f73819fd99b45669100adda813d89e4>:0
at Microsoft.Identity.Client.TokenCache.SaveAccessAndRefreshToken (Microsoft.Identity.Client.Internal.Requests.AuthenticationRequestParameters requestParams, Microsoft.Identity.Client.Internal.OAuth2.TokenResponse response) [0x00291] in <7f73819fd99b45669100adda813d89e4>:0
at Microsoft.Identity.Client.Internal.Requests.RequestBase.SaveTokenResponseToCache () [0x001a8] in <7f73819fd99b45669100adda813d89e4>:0
at Microsoft.Identity.Client.Internal.Requests.RequestBase.PostTokenRequest () [0x00008] in <7f73819fd99b45669100adda813d89e4>:0
at Microsoft.Identity.Client.Internal.Requests.RequestBase+d__33.MoveNext () [0x00360] in <7f73819fd99b45669100adda813d89e4>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535
at Microsoft.Identity.Client.PublicClientApplication+d__18.MoveNext () [0x000d2] in <7f73819fd99b45669100adda813d89e4>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
…

bug

Most helpful comment

@jennyf19 thank you so much you are really fast.

All 8 comments

@muhammetsahin Thank you so much for letting us know...was able to reproduce and will have a fix out shortly.
cc: @jmprieur @henrik-me

@muhammetsahin We have fixed this in 1.1.4-preview

Manual testing done w/Android device, iOS device and iOS simulator

cc: @jmprieur @henrik-me

@jennyf19 thank you so much you are really fast.

This issue is still in the latest versions - i was messing with this for an hour before rolling back all the way to version 1.1.2 preview 0008 when it just worked immediately. Why has the fix not been included in the updated versions?

@Journeyman42 This particular bug was not an issue for v2, as we moved the code to a common repository for refactoring, so I think you're running into a different issue. The format of the cache between MSALv1 and v2 has changed, so now apps that run on iOS native msal can share cache with Xamarin .NET msal apps, so the way we access and use keychain has changed.

Sounds like you've already spent some time on this, but if you want to double check the keychain groups
and try with Msalv2, we'd be interested in your results. Please open an issue in the MSAL repo with your specific set-up and logs/stack trace.

@jennyf19 Appreciate the speedy response, see someone else is making good use of their Saturday evening!

I don't believe it is the keychain issue - initially i was indeed seeing an error, using the very latest version of the library, informing me the TeamID was null and I then went through the steps I found on your blog to add Keychain Access Groups to Entitlement.plist

Having been through all that, the app still crapped out at the same point, only this time it was saying 'Object not set to an instance of an object'. It was that which brought me to this page, and prompted me to downgrade to the much older version referenced, at which point as mentioned it just started working instantly

@jennyf19 Sorry, another question - I've just gone back through the link above checking everything again and one thing i noticed is the direction in AppDelegate to use SetBrokerContinuationEventArgs instead of SetAuthenticationContinuationEventArgs, only the former isn't available in the very latest version of Microsoft.Identity.Client?

@Journeyman42 - That is not correct. We do not have broker for MSAL yet. I will update the wiki. It should be:

public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
        if (!AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(url))
        {
                return false;
        }
        return true;
}

Can you open an issue in MSAL with the logs and stack trace? this will help us investigate the issue you're running into. thanks.

Was this page helpful?
0 / 5 - 0 ratings