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.

System.ArgumentNullException from TokenCacheAccessor.CreateRecord, Xamarin.iOS

See original GitHub issue

Which Version of MSAL are you using ? MSAL 2.1.0-preview

Which platform has the issue? Xamarin iOS

What authentication flow has the issue? Mobile - iOS

Repro

public async Task<AuthenticationResult> AcquireTokenAsync() => await publicClientApplication.AcquireTokenAsync(AuthConfig.Scopes, new UIParent());

Expected behavior An token is retrieved and a user record is created in the token cache.

Actual behavior It looks as though the TokenCacheAccessor is failing to create a record after attempting to acquire a token from Azure B2C. It seems specific to the specific B2C policy we’re using. The same workflow works fine in Android, and if I do not provide an Authority to MSAL in iOS, this exception is not thrown.

It doesn’t seem there’s much I can do, as this exception is thrown from within the depths of MSAL, and there don’t seem to be any APIs exposed to handle caching or user records directly.

This issue occurs on both simulator and device. I’ve tried erasing all content and settings on the simulator, doesn’t help.

The fact that I can log in successfully using iOS with the same code but a different B2C policy is interesting. It looks like there’s a particular configuration within this B2C policy that is causing the Xamarin.iOS MSAL library to throw this exception.

Has anyone else encountered this problem?

Here’s the exception:

System.ArgumentNullException: Value cannot be null. Parameter name: str 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.TokenCacheAccessor.CreateRecord (System.String account, System.String service, System.String generic, System.Int32 type, System.String value) [0x00014] in <2a97cd931f1242d58d9f88cc99534e1d>:0 at Microsoft.Identity.Core.TokenCacheAccessor.Save (System.String account, System.String service, System.String generic, System.Int32 type, System.String value) [0x00000] in <2a97cd931f1242d58d9f88cc99534e1d>:0 at Microsoft.Identity.Core.TokenCacheAccessor.SaveAccount (Microsoft.Identity.Core.Cache.MsalAccountCacheItem item) [0x00046] in <2a97cd931f1242d58d9f88cc99534e1d>:0 at Microsoft.Identity.Core.Telemetry.TelemetryTokenCacheAccessor.SaveAccount (Microsoft.Identity.Core.Cache.MsalAccountCacheItem item, Microsoft.Identity.Core.RequestContext requestContext) [0x0001f] in <2a97cd931f1242d58d9f88cc99534e1d>:0 at Microsoft.Identity.Client.TokenCache.SaveAccessAndRefreshToken (Microsoft.Identity.Client.Internal.Requests.AuthenticationRequestParameters requestParams, Microsoft.Identity.Core.OAuth2.MsalTokenResponse response) [0x00178] in <2a97cd931f1242d58d9f88cc99534e1d>:0 at Microsoft.Identity.Client.Internal.Requests.RequestBase.SaveTokenResponseToCache () [0x001bc] in <2a97cd931f1242d58d9f88cc99534e1d>:0 at Microsoft.Identity.Client.Internal.Requests.RequestBase.PostTokenRequest () [0x00008] in <2a97cd931f1242d58d9f88cc99534e1d>:0 at Microsoft.Identity.Client.Internal.Requests.RequestBase+<RunAsync>d__48.MoveNext () [0x00399] in <2a97cd931f1242d58d9f88cc99534e1d>:0 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__22.MoveNext () [0x000fb] in <2a97cd931f1242d58d9f88cc99534e1d>:0 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__14.MoveNext () [0x0009b] in <2a97cd931f1242d58d9f88cc99534e1d>:0 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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
PostImpaticacommented, Oct 16, 2018

@jennyf19 Thank you!

0reactions
jennyf19commented, Oct 17, 2018

@helzgate Here is the release for Msal 2.2.1-preview with the fixes and on nuget

If this release does not address your issue, we can reopen this one or start a new one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

xamarin forms: System.ArgumentNullException has been ...
I am using webview for parsing my HTML data. For this, I am using a custom render. In the Main Project: public class...
Read more >
ArgumentNullException on iOS when setting Image's ...
I'm developing a crossplatform app using the Xamarin.Forms framework. I have noticed a problem with Visual Studio 2019 16.5 Preview 3.0 and ...
Read more >
System.ArgumentNullException: Value cannot be null. ...
I have a problema in a grid in xamarin.ios. If any values is null then throw: Send a Example, . Project XamarinGrid.Android =>...
Read more >
ArgumentNullException Class (System)
An ArgumentNullException exception is thrown when a method is invoked and at least one of the passed arguments is null but should never...
Read more >
System.ArgumentNullException Value cannot be null. ...
Hello, it seems that is working fine here. Do you have a simple example to reproduce it ? Anyway, just tell to you,...
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