WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

WebView2 types exist in both Microsoft.Web.WebView2.Core and Windows App SDK

Open Daniellled opened this issue 2 years ago • 2 comments

Describe the bug

if you have a WPF application that uses WebView2 and also attempt to use WindowsAppSDK for functionality such as notifications.

The instant you add any code that uses CoreWebView2NavigationStartingEventArgs you receive.

CS0433 The type 'CoreWebView2NavigationStartingEventArgs' exists in both 'Microsoft.Web.WebView2.Core, Version=1.0.1823.32, Culture=neutral, PublicKeyToken=2a8ab48044d2601e' and 'Microsoft.WinUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=de31ebe4ad15742b'

Steps to reproduce the bug

To reproduce I followed these steps https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/wpf-plus-winappsdk#configure-your-wpf-project-for-windows-app-sdk-support followed by these https://learn.microsoft.com/en-us/microsoft-edge/webview2/get-started/wpf (I omitted the .NET Framework stuff since the app is .NET 6)

The instant I add in this code things quit working

void EnsureHttps(object sender, CoreWebView2NavigationStartingEventArgs args)
{
   String uri = args.Uri;
   if (!uri.StartsWith("https://"))
   {
      webView.CoreWebView2.ExecuteScriptAsync($"alert('{uri} is not safe, try an https link')");
      args.Cancel = true;
   }
}

I have uploaded an example that reproduces the issue.

TestAppSDKWebView.zip

Expected behavior

The WPF WebView2 control functions with Windows App SDK

Screenshots

No response

NuGet package version

Windows App SDK 1.3.2: 1.3.230602002

Packaging type

Packaged (MSIX), Unpackaged

Windows version

Windows 10 version 2004 (19041, May 2020 Update)

IDE

Visual Studio 2022

Additional context

No response

Daniellled avatar Aug 22 '23 13:08 Daniellled

This also seems to be the case for a C++ WinUI3 app using the Windows Apps SDK. Installing the Microsoft.Web.WebView2 NuGet package causes builds to fail while processing winmd files (MDMERGE) due to duplicate types found.

MDMERGE : error MDM2009: Duplicate type Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext found processing metadata file packages\Microsoft.Web.WebView2.1.0.2420.47\lib\Microsoft.Web.WebView2.Core.winmd, type already exists in file packages\Microsoft.WindowsAppSDK.1.5.240311000\lib\uap10.0\Microsoft.Web.WebView2.Core.winmd.

This is unfortunate since the version of the WebView2 API included with the WASDK is several months out of date compared to what is available via the WebView2 Nuget.

Deleting the packages\Microsoft.WindowsAppSDK.1.5.240311000\lib\uap10.0\Microsoft.Web.WebView2.Core.winmd file seems to be enough to get builds to complete successfully.

Windows Apps SDK: 1.5.240311000 WebView2 API Available through WASDK: 1.0.2210.551 WebView2 API Available through Nuget: 1.0.2420.47

aschultz avatar Apr 02 '24 02:04 aschultz

@bpulliam Is this #4249, or some other derivative of #1856?

zadjii avatar Apr 21 '24 12:04 zadjii

I agree this is the same as microsoft/WindowsAppSDK#4249, which is fixed in 1.6.240701003-experimental2.

codendone avatar Jul 10 '24 01:07 codendone