System.ArgumentNullException from TokenCacheAccessor.CreateRecord, Xamarin.iOS
See original GitHub issueWhich 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.ConfiguredTaskAwaitable
1+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:
- Created 5 years ago
- Comments:11 (2 by maintainers)
Top GitHub Comments
@jennyf19 Thank you!
@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.