microsoft-authentication-library-for-dotnet: AcquireTokenInteractive crashes on UWP app for ARM64

Version of Nuget Microsoft.Identity.Client 4.19.0

Platform: UWP on ARM64

In a UWP Desktop App, running on ARM64, we want to authenticate for OneDrive, using the method IPublicClientApplication.AcquireTokenInteractive(…).ExecuteAsync();

Repro

private readonly string[] m_scopes = new[] { "Files.ReadWrite" };

IPublicClientApplication s_publicClientApp = PublicClientApplicationBuilder.Create("MyAppKeyForOneDrive")
					.WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
					.Build();
IEnumerable<IAccount> accounts = await s_publicClientApp.GetAccountsAsync();
IAccount firstAccount = accounts?.FirstOrDefault();
AuthenticationResult authResult;
if (firstAccount != null)
{
	authResult = await s_publicClientApp.AcquireTokenSilent(m_scopes, firstAccount).ExecuteAsync();
}
else
{
	authResult = await s_publicClientApp.AcquireTokenInteractive(m_scopes).ExecuteAsync();
}

Expected behavior User is shown the login popup to enter credentials, and after successful login, the code receives a valid authResult.

Actual behavior On ARM64, the app crashes with an unrecoverable exception in SharedLibrary.dll.

Additional context/ Logs / Screenshots Please note that the very same code works perfectly in x64.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 65 (32 by maintainers)

Most upvoted comments

I am also disappointed to hear this issue has been closed without fixing it. This is especially frustrating for new developers picking up this library - they will all run into the same problem eventually. I have read through the whole thread now and haven’t seen an explanation on why a) this cannot be fixed in the library and b) what UseDotNetNativeSharedAssemblyFrameworkPackage actually does and why it is a functioning workaround

If it’s not a bug in the MSAL library, where is the crash originating from then?

Possible workaround - add this to the csproj:

<UseDotNetNativeSharedAssemblyFrameworkPackage>false</UseDotNetNativeSharedAssemblyFrameworkPackage>

This solve my problem

Maybe this is a good time to consider switching to System.Json.Text. The Graph SDK already migrated to it a few months back. Besides likely fixing this bug and getting faster (de)serialization, having less dependencies would also help mobile app developers to shrink their app sizes (Newtonsoft.Json isn’t exactly the smallest library)

larger app package and maybe a slower startup?

that’s certainly something that I’d want to avoid… 😐

Possible workaround - add this to the csproj:

<UseDotNetNativeSharedAssemblyFrameworkPackage>false</UseDotNetNativeSharedAssemblyFrameworkPackage>

This solved my problem too. Thanks

@myokeeh - no idea where they come from, they are not from MSAL SDK. It is possible that an app or a dependency declares smth like

        [DllImport("User32.dll", CallingConvention = CallingConvention.StdCall)]
        internal static extern IntPtr GetDC(IntPtr hWnd);

I think these can trigger warnings like above, but does not mean the app will crash, for example if the method is not actually called.

Hello. I try again with new version (4.28.1) and still it’s failing. Here you have current log … Just FYI when failing, debugger is asking for find some source code Dispensers.NativeFormats.cs , maybe it helps

GET TOKEN !!!!!!!!!!!
(False) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15] Found 0 cache accounts and 0 broker accounts
(False) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15] Returning 0 accounts
(False) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] MSAL MSAL.UAP with assembly version '4.28.1.0'. CorrelationId(CORRELATION_ID)
(False) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] === AcquireTokenSilent Parameters ===
(False) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] LoginHint provided: False
(True) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] Account provided: false
(False) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] ForceRefresh: False
(True) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] 
=== Request Data ===
Authority Provided? - True
Client Id - CLIENT_ID
Scopes - Directory.ReadWrite.All Files.ReadWrite.All User.Read
Redirect Uri - urn:ietf:wg:oauth:2.0:oob
Extra Query Params Keys (space separated) - 
ClaimsAndClientCapabilities - 
Authority - https://login.microsoftonline.com/common/
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint - 
IsBrokerConfigured - False
HomeAccountId - 
CorrelationId - CORRELATION_ID

(True) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] === Token Acquisition (SilentRequest) started:
	Authority: https://login.microsoftonline.com/common/
	Scope: Directory.ReadWrite.All Files.ReadWrite.All User.Read
	ClientId: CLIENT_ID
	
Exception thrown: 'Microsoft.Identity.Client.MsalUiRequiredException' in Microsoft.Identity.Client.dll
Exception thrown: 'Microsoft.Identity.Client.MsalUiRequiredException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.Identity.Client.MsalUiRequiredException' in System.Private.CoreLib.dll
(True) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] MSAL.UAP.4.28.1.0.MsalUiRequiredException: 
	ErrorCode: user_null
Microsoft.Identity.Client.MsalUiRequiredException: No account or login hint was passed to the AcquireTokenSilent call. 
   at Microsoft.Identity.Client.Internal.Requests.Silent.SilentRequest.<ExecuteAsync>d__5.MoveNext() + 0x224
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24
   at Microsoft.Identity.Client.Internal.Requests.Silent.SilentRequest.<ExecuteAsync>d__5.MoveNext() + 0x654
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xac
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x58
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x24
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.<RunAsync>d__13.MoveNext() + 0x194

	StatusCode: 0 
	ResponseBody:  
	Headers: 
Exception thrown: 'Microsoft.Identity.Client.MsalUiRequiredException' in Microsoft.Identity.Client.dll
Exception thrown: 'Microsoft.Identity.Client.MsalUiRequiredException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.Identity.Client.MsalUiRequiredException' in System.Private.CoreLib.dll
>>>>>>>>>>>>>>> No account or login hint was passed to the AcquireTokenSilent call. 
GET NEW TOKEN !!!!!!!!!!!
(False) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] MSAL MSAL.UAP with assembly version '4.28.1.0'. CorrelationId(OTHER_CORRELATION_ID)
(False) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] === InteractiveParameters Data ===
LoginHint provided: False
User provided: False
UseEmbeddedWebView: NotSpecified
ExtraScopesToConsent: 
Prompt: not_specified
HasCustomWebUi: False

(True) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] 
=== Request Data ===
Authority Provided? - True
Client Id - CLIENT_ID
Scopes - Directory.ReadWrite.All Files.ReadWrite.All User.Read
Redirect Uri - urn:ietf:wg:oauth:2.0:oob
Extra Query Params Keys (space separated) - 
ClaimsAndClientCapabilities - 
Authority - https://login.microsoftonline.com/common/
ApiId - AcquireTokenInteractive
IsConfidentialClient - False
SendX5C - False
LoginHint - 
IsBrokerConfigured - False
HomeAccountId - 
CorrelationId - OTHER_CORRELATION_ID

(True) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] === Token Acquisition (InteractiveRequest) started:
	Authority: https://login.microsoftonline.com/common/
	Scope: Directory.ReadWrite.All Files.ReadWrite.All User.Read
	ClientId: CLIENT_ID
	
(True) MSAL 4.28.1.0 MSAL.UAP N/A [03/28/2021 15:59:15 - ] Fetching instance discovery from the network from host login.microsoftonline.com. Endpoint https://login.microsoftonline.com/common/discovery/instance. 
onecore\com\combase\dcomrem\preventrundownbias.cpp(1310)\combase.dll!00007FFC167B2B78: (caller: 00007FFC167B29B8) LogHr(2) tid(2cd8) 80070005 Access is denied.
Unhandled exception at 0x00007FFBE7B878E8 (mrt100_app.dll) in Wallet.exe: 0xC0000602:  A fail fast exception occurred. Exception handlers will not be invoked and the process will be terminated immediately.

We are facing the same issue. I’m trying to run it on the sample provided here https://github.com/azure-samples/active-directory-dotnet-native-uwp-v2 Version of Nuget Microsoft.Identity.Client 4.27.0

I wonder if WAM will fare better here. If you have the time, could you try to the WAM broker instead of the browser control ? This is described here https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/wam

It’s a different experience that’s more integrated with Windows and which we will probably enable by default at some point. From your point of view you just have to register another redirect URI and add .WithBroker(true). The link has more details.