Skip to content

WebView2

Sahil Malik edited this page Aug 5, 2021 · 15 revisions

What is WebView2

A modern embedded browser based on Microsoft Edge, capable of performing Windows Hello, log-in with FIDO keys, etc. This browser replaces the old embedded WebView, based on an outdated version of Internet Explorer.

Where is it available?

  • All Windows versions
  • MSAL version 4.28.0 and higher
  • WebView2 runtime must be installed on the machine

Evergreen runtime

WebView2 runtime is not available on all Windows machines by default. Edge needs to be installed. Applications may choose to install it or guide the end users to install it. Installing it requires admin access.

Changes to call pattern

var pca = PublicClientApplicationBuilder
    .Create("client_id")
    .WithDesktopFeatures()
    .Build()

Behaviour

Embedded WebView Default WebView
.NET Fx WebView2, fallback to Legacy Embedded
.NET Core WebView2, fallback to Legacy* Embedded
.NET 5 WebView2, fallback to Legacy* Embedded

*In .NET Core and .NET 5, fallback to legacy WebView is available starting in MSAL 4.30.0.

Troubleshooting

WebView2 on .NET Framework

There's a scenario when an app that targets .NET Framework and references MSAL.NET NuGet package tries to acquire token interactively with WebView2 embedded browser, WebView2 will throw exceptions. These errors can be System.BadImageFormatException: An attempt was made to load a program with an incorrect format. or System.DllNotFoundException: 'Unable to load DLL 'WebView2Loader.dll': The specified module could not be found. (As of MSAL.NET 4.32.0 these exceptions are wrapped into MsalClientException.)

This occurs because of an existing bug in the WebView2 SDK on .NET Classic platform because it can't figure out the target platform of the dependencies. One possible workaround is to add a <PlatformTarget> with values AnyCPU, x86, or x64 to your app's project file. (x86 or x64 have to match the target framework of the WebView2 installed on the machine.) Another workaround is to add <PlatformTarget>AnyCPU</PlatformTarget> in your app's project file and also directly reference WebView2 NuGet. For details, see issues #2482, #730.

Getting started with MSAL.NET

Acquiring tokens

Desktop/Mobile apps

Web Apps / Web APIs / daemon apps

Advanced topics

News

FAQ

Other resources

Clone this wiki locally