Microsoft-authentication-library-for-dotnet: [Bug] MSAL NuGet package needs an rd.xml to work correctly in UWP apps

Created on 7 Feb 2020  路  14Comments  路  Source: AzureAD/microsoft-authentication-library-for-dotnet

Which Version of MSAL are you using ?
MSAL 4.8.1

Platform
UWP

What authentication flow has the issue?

  • Desktop / Mobile

    • [x] Interactive

Is this a new or existing app?
a. The app is in production, and I have upgraded to a new version of MSAL

Repro
Create a UWP app project in VS 2019. Add auth to it, as per https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-windows-uwp

Enable .NET Native compilation and run the app. Sign-in will throw an exception with the following error message: Authorize endpoint was not found in the openid configuration

Expected behavior
Auth should work.

Actual behavior
Exception is thrown.

Possible Solution

You should ship an rd.xml containing the following directive (or similar):

<Assembly Name="Microsoft.Identity.Client" Dynamic="Required All" />

cf https://devblogs.microsoft.com/dotnet/net-native-deep-dive-making-your-library-great/

Fixed P2 bug Mobile-UWP workaround exists

All 14 comments

Please use MSAL 4.7, it had that file. Will add it back, I think we removed it because we forgot what it was doing.

Ok, I think I understand this better now. We've done some work to move away from DataContract serializer to Newtonsoft.Json serializer. This must have done smth to the .net native feature, similar to how linking stopped working on Xamarin.

Changes were done in 4.8 timeline, so 4.7 should still work.

I can't repro this, what is the exception that you are getting?

I forget the exact exception, but basically sign-in attempts throw and fail.

If you still can't repro it, I'll get more precise details.

Okay,

The exception:

{"Authorize endpoint was not found in the openid configuration"}    Microsoft.Identity.Client.MsalClientException

The stack trace:

Microsoft.Identity.Client.dll!Microsoft.Identity.Client.Instance.AuthorityEndpointResolutionManager.ResolveEndpointsAsync(Microsoft.Identity.Client.AuthorityInfo authorityInfo, string userPrincipalName, Microsoft.Identity.Client.Core.RequestContext requestContext)    Unknown Non-user code. PDB file was not present when IL code was compiled to native.
    [Resuming Async Method]     Annotated Frame
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.CallMoveNext.AnonymousMethod__3_0(object state) Line 856   C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.ContextCallback.Invoke(object state)    C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 166  C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 124  C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.CallMoveNext() Line 859    C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Action.Invoke()   C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Line 351    C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Action.Invoke()   C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining, ref System.Threading.Tasks.Task currentTask) Line 677 C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3164  C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishStageThree() Line 2223 C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<Microsoft.Identity.Client.Instance.TenantDiscoveryResponse>.TrySetResult(Microsoft.Identity.Client.Instance.TenantDiscoveryResponse result) Line 424 C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.Identity.Client.Instance.TenantDiscoveryResponse>.SetResult(Microsoft.Identity.Client.Instance.TenantDiscoveryResponse result) Line 530 C#  Non-user code. Symbols loaded.
    [Completed] Microsoft.Identity.Client.dll!Microsoft.Identity.Client.Instance.AuthorityEndpointResolutionManager.DiscoverEndpointsAsync(string openIdConfigurationEndpoint, Microsoft.Identity.Client.Core.RequestContext requestContext)    Unknown Non-user code. PDB file was not present when IL code was compiled to native.
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.CallMoveNext.AnonymousMethod__3_0(object state) Line 856   C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.ContextCallback.Invoke(object state)    C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 166  C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 124  C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.CallMoveNext() Line 859    C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Action.Invoke()   C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0() Line 351    C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Action.Invoke()   C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining, ref System.Threading.Tasks.Task currentTask) Line 677 C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishContinuations() Line 3164  C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishStageThree() Line 2223 C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Threading.Tasks.Task<Microsoft.Identity.Client.Instance.TenantDiscoveryResponse>.TrySetResult(Microsoft.Identity.Client.Instance.TenantDiscoveryResponse result) Line 424 C#  Non-user code. Symbols loaded.
    System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.Identity.Client.Instance.TenantDiscoveryResponse>.SetResult(Microsoft.Identity.Client.Instance.TenantDiscoveryResponse result) Line 530 C#  Non-user code. Symbols loaded.
    [Completed] Microsoft.Identity.Client.dll!Microsoft.Identity.Client.OAuth2.OAuth2Client.ExecuteRequestAsync<Microsoft.Identity.Client.Instance.TenantDiscoveryResponse>(System.Uri endPoint, System.Net.Http.HttpMethod method, Microsoft.Identity.Client.Core.RequestContext requestContext, bool expectErrorsOn200OK) Unknown Non-user code. PDB file was not present when IL code was compiled to native.
    Microsoft.Identity.Client.dll!Microsoft.Identity.Client.OAuth2.OAuth2Client.ExecuteRequestAsync<System.__Canon>(System.Uri endPoint, System.Net.Http.HttpMethod method, Microsoft.Identity.Client.Core.RequestContext requestContext, bool expectErrorsOn200OK) Unknown Non-user code. PDB file was not present when IL code was compiled to native.
    Microsoft.Identity.Client.dll!Microsoft.Identity.Client.OAuth2.OAuth2Client.ExecuteRequestAsync<System.__Canon>(System.Uri endPoint, System.Net.Http.HttpMethod method, Microsoft.Identity.Client.Core.RequestContext requestContext, bool expectErrorsOn200OK) Unknown Non-user code. PDB file was not present when IL code was compiled to native.

@mfeingol : which authority did you use?

I'm not specifying an authority, so whatever the default is.

To reiterate: this issue only repros with .NET Native compilation enabled and Microsoft.Identity.Client not explicitly included in Runtime Directives.

Thanks @mfeingol : I understand fully now.

@mfeingol, thank you for reporting this bug. I spent over a week trying to fix this and would never have thought to modify the rd.xml file. I made your suggested change and it now works.

@bgavrilMS @jmprieur : I'm not sure what the fix is from our side here? Is this just adding the file back?

@bgavrilMS: here's a repro.

Build in x64 debug and observe that you can sign in by clicking on the Log in button.

Then build x64 release and try again. Instead of a successful login, the library will throw Microsoft.Identity.Client.MsalClientException: client info is null

MsalDotNetNative.zip

Please note that you will need to set your own client id and redirect id in MainPage.xaml.cs

Thanks.

This is causing lots of problems.

Was this page helpful?
0 / 5 - 0 ratings