question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null reference on iOS AcquireTokenAsync(Scopes, UIParent)

See original GitHub issue

name: Bug report about: Create a report to help us improve


Which Version of MSAL are you using ? MSAL 2.2.1-preview AND MSAL 2.3.1

Which platform has the issue? xamarin iOS

What authentication flow has the issue?

  • Mobile
    • [X ] Xamarin.iOS

What is the identity provider ?

  • Azure AD
  • [ X] Azure AD B2C

If B2C, what social identity did you use? Microsoft Account

Repro

result = await _pca.AcquireTokenAsync(AuthConstants.Scopes, _uiParent);

Expected behavior After a login on the webview I should be navigated back to the application and my token should be stored.

Actual behavior After the webview is closed the application is exitting with an null reference exception.

Additional context/ Logs / Screenshots

at Foundation.NSString…ctor (System.String str) [0x00009] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/Foundation/NSString.cs:139 at Foundation.NSData.FromString (System.String s, Foundation.NSStringEncoding encoding) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/Foundation/NSData.cs:208 at Foundation.NSData.op_Implicit (System.String s) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/Foundation/NSData.cs:214 at Microsoft.Identity.Core.iOSTokenCacheAccessor.CreateRecord (System.String account, System.String service, System.String generic, System.Int32 type, System.String value) [0x00014] in <420cc22f37f340a0a560df4a374dbe4a>:0 at Microsoft.Identity.Core.iOSTokenCacheAccessor.Save (System.String account, System.String service, System.String generic, System.Int32 type, System.String value) [0x00000] in <420cc22f37f340a0a560df4a374dbe4a>:0 at Microsoft.Identity.Core.iOSTokenCacheAccessor.SaveAccount (Microsoft.Identity.Core.Cache.MsalAccountCacheItem item) [0x00033] in <420cc22f37f340a0a560df4a374dbe4a>:0 at Microsoft.Identity.Core.Telemetry.TelemetryTokenCacheAccessor.SaveAccount (Microsoft.Identity.Core.Cache.MsalAccountCacheItem item) [0x00000] in <420cc22f37f340a0a560df4a374dbe4a>:0 at Microsoft.Identity.Core.Telemetry.TelemetryTokenCacheAccessor.SaveAccount (Microsoft.Identity.Core.Cache.MsalAccountCacheItem item, Microsoft.Identity.Core.RequestContext requestContext) [0x0001f] in <420cc22f37f340a0a560df4a374dbe4a>:0 at Microsoft.Identity.Client.TokenCache.SaveAccessAndRefreshToken (Microsoft.Identity.Client.Internal.Requests.AuthenticationRequestParameters requestParams, Microsoft.Identity.Core.OAuth2.MsalTokenResponse response) [0x00178] in <420cc22f37f340a0a560df4a374dbe4a>:0 at Microsoft.Identity.Client.Internal.Requests.RequestBase.CacheTokenResponseAndCreateAuthenticationResult (Microsoft.Identity.Core.OAuth2.MsalTokenResponse msalTokenResponse) [0x00181] in <420cc22f37f340a0a560df4a374dbe4a>:0 at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest+<ExecuteAsync>d__9.MoveNext () [0x00168] in <420cc22f37f340a0a560df4a374dbe4a>:0 — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/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/12.0.0.15/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/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Microsoft.Identity.Client.Internal.Requests.RequestBase+<RunAsync>d__18.MoveNext () [0x0016b] in <420cc22f37f340a0a560df4a374dbe4a>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/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/12.0.0.15/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/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Microsoft.Identity.Client.PublicClientApplication+<AcquireTokenForLoginHintCommonAsync>d__23.MoveNext () [0x00106] in <420cc22f37f340a0a560df4a374dbe4a>:0 — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/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/12.0.0.15/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/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 at Microsoft.Identity.Client.PublicClientApplication+<AcquireTokenAsync>d__15.MoveNext () [0x0009b] in <420cc22f37f340a0a560df4a374dbe4a>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/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/12.0.0.15/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/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 at MyAppMobile.Services.AuthenticationService+<GetAccessToken>d__5.MoveNext () [0x001ee] in /Users/vcs12345/Documents/GIT/MyApp-Mobile/MyAppMobile/MyAppMobile/Services/AuthenticationService.cs:64 — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/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/12.0.0.15/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/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 at MyAppMobile.ViewModels.LoginViewModel+<StartLoginProcess>d__11.MoveNext () [0x0005f] in /Users/vcs12345/Documents/GIT/MyApp-Mobile/MyAppMobile/MyAppMobile/ViewModels/LoginViewModel.cs:71 — End of stack trace from previous location where exception was thrown — at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/Foundation/NSAction.cs:178 — End of stack trace from previous location where exception was thrown — at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/UIKit/UIApplication.cs:79 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.0.0.15/src/Xamarin.iOS/UIKit/UIApplication.cs:63 at MyAppMobile.iOS.Application.Main (System.String[] args) [0x00001] in /Users/vcs12345/Documents/GIT/MyApp-Mobile/MyAppMobile/MyAppMobile.iOS/Main.cs:17

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Bloodyairtimercommented, Nov 5, 2018

@Bloodyairtimer did your issue get resolved?

Yes, adding the User’s Object ID to the claim resolved my issue. Issue can be closed.

0reactions
jennyf19commented, Nov 2, 2018

@Bloodyairtimer did your issue get resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullReferenceException in ...
A null reference exception is thrown. ... Passing in a new UIParent seems to resolve this issue... var authResult = await Client.AcquireTokenAsync ......
Read more >
Microsoft.Identity.Client version 1.1.1-preview0040 doesn't ...
AcquireTokenAsync (Scopes, uIParent) . I can get uIParent from the Android App, but it doesn't work 100%. It opens a login dialog, ...
Read more >
Authenticate Users with Azure Active Directory B2C
AuthenticationClient .AcquireTokenInteractive(Constants.Scopes) .WithPrompt(Prompt.SelectAccount) .WithParentActivityOrWindow(App.UIParent) .
Read more >
MSAL.PS
Attempts to acquire the access token from cache. Access token is considered a match if it AT LEAST contains all the requested scopes....
Read more >
Adding Authentication and Authorization with Azure AD B2C
Find out how to integrate Azure AD B2C authentication and authorization to a Xamarin app using the MSAL client library to gain access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found