microsoft-authentication-library-for-dotnet icon indicating copy to clipboard operation
microsoft-authentication-library-for-dotnet copied to clipboard

[Bug] MSAL fails to compile or to run in self-contained WinUI3 app

Open anpin opened this issue 7 months ago • 9 comments

Library version used

4.61.3

.NET version

8.0.204

Scenario

PublicClient - desktop app

Is this a new or an existing app?

The app is in production, and I have upgraded to a new version of MSAL

Issue description and reproduction steps

MSAL 4.61.3 fails to compile targeting WinUI3 self-contained deployment with Payload contains two or more files with the same destination path 'Microsoft.Web.WebView2.Core.dll'

Above error is fixed by using <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240701003-experimental2" /> see https://github.com/microsoft/microsoft-ui-xaml/issues/5689#issuecomment-2206866464. However authentication fails on runtime due to missing webview2 assembly as the version in Microsoft.WindowsAppSDK is newer than MSAL

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Web.WebView2.Core, Version=1.0.864.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e'. The system cannot find the file specified.
File name: 'Microsoft.Web.WebView2.Core, Version=1.0.864.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e'
   at Microsoft.Identity.Client.Desktop.WebView2WebUi.WebView2WebUiFactory.IsWebView2Available()
   at Microsoft.Identity.Client.Desktop.WebView2WebUi.WebView2WebUiFactory.CreateAuthenticationDialog(CoreUIParent coreUIParent, WebViewPreference useEmbeddedWebView, RequestContext requestContext)
   at Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.CreateWebAuthenticationDialog()
   at Microsoft.Identity.Client.Internal.AuthCodeRequestComponent.FetchAuthCodeAndPkceVerifierAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.GetTokenResponseAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Internal.Requests.InteractiveRequest.ExecuteAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.<>c__DisplayClass11_1.<<RunAsync>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.Identity.Client.Utils.StopwatchService.MeasureCodeBlockAsync(Func`1 codeBlock)
   at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ApiConfig.Executors.PublicClientExecutor.ExecuteAsync(AcquireTokenCommonParameters commonParameters, AcquireTokenInteractiveParameters interactiveParameters, CancellationToken cancellationToken)

Is there a way to override which version of webview should be used?

related to https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/3583 https://github.com/microsoft/microsoft-ui-xaml/issues/5689 https://github.com/microsoft/WindowsAppSDK/issues/2492

Relevant code snippets

No response

Expected behavior

No response

Identity provider

Azure B2C Basic Policy

Regression

No response

Solution and workarounds

No response

anpin avatar Jul 05 '24 11:07 anpin