microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.35k stars 678 forks source link

BlazorWebView & WindowsAppSDK - WebView2 DLL missmatch #10121

Open vsfeedback opened 5 days ago

vsfeedback commented 5 days ago

This issue has been moved from a ticket on Developer Community.


[severity:I’m unable to use this version]
We are developing an WPF Blazor Hybrid app. The app also makes use of various features provided by the WindowsAppSDK library. Since we updated the WindowsAppSDK to version 1.6 the BlazorWebView cannot be instantiated anymore due to the following runtime exception:

System.Windows.Markup.XamlParseException
  HResult=0x80131501
  Message='The invocation of the constructor on type 'Microsoft.AspNetCore.Components.WebView.Wpf.BlazorWebView' that matches the specified binding constraints threw an exception.' Line number '15' and line position '10'.
  Source=PresentationFramework
  StackTrace:
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at BlazorWpf1.MainWindow.InitializeComponent() in C:\Users\jonas\Downloads\BlazorWpf1\BlazorWpf1\MainWindow.xaml:line 1

  This exception was originally thrown at this call stack:

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'Microsoft.Web.WebView2.Wpf, Version=1.0.2592.51, Culture=neutral, PublicKeyToken=2a8ab48044d2601e'. The system cannot find the file specified.

The following two NuGet packages that we are using seem to be causing this conflict:

<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebView.Wpf" Version="8.0.92" />
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
</ItemGroup>

The following findings where the result of our own investigation of the problem:

We noticed that the VisualStudio update also has an influence. With version 17.10 the project with the lastest versions of the libraries could not be compiled and raised the compilation error:

Severity    Code    Description Project File    Line    Suppression State   Details
Error (active)      This version of the Windows App SDK requires Microsoft.Windows.SDK.NET.Ref 10.0.17763.38 or later.
    Please update to .NET SDK 6.0.134, 6.0.426, 8.0.109, 8.0.305 or 8.0.402 (or later).
    Or add a temporary Microsoft.Windows.SDK.NET.Ref reference which can be added with:
        <PropertyGroup>
            <WindowsSdkPackageVersion>10.0.17763.38</WindowsSdkPackageVersion>
        </PropertyGroup>

Updating to 17.11 fixed the compilation error but the runtime error remained. With VisualStudio Version 17.10, adding the WindowsSdkPackageVersion tag in the project file as states in the compiler error message allowed for successful compilation but the runtime error remains.

The problem can be reproduced by the following steps:

  1. Follow the steps of the official tutorial for a minimal WPF BlazorHybrid app: https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/tutorials/wpf?view=aspnetcore-8.0
  2. Add a Package reference to the Microsoft.WindowsAppSDK version 1.6+
  3. Set the target framework of the project to at least net8.0-windows10.0.17763.0
  4. Run the app to provoke the error

Attached is a premade sample project to reproduce the problem:

BlazorWpf1.zip


Original Comments

Feedback Bot on 10/29/2024, 07:48 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

karkarl commented 4 days ago

@codendone is this error something you've encountered before?

oggy22 commented 3 days ago

From the logs, it looks like you are using an older WebView2 SDK Microsoft.Web.WebView2.Wpf, Version=1.0.2592.51. Can you please try with the latest SDKs https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.2895-prerelease OR https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.2849.39

pensiveCarson commented 4 hours ago

The example project does not have a direct reference to the Microsoft.Web.Webview2. But it is referenced by both packages Microsoft.AspNetCore.Components.WebView.WPF and Microsoft.WindowsAppSDK in version 1.0.2651.64 If I manually add the latest 1.0.2849.39 (or latest prerelease 1.0.2895-prerelease ) version to the project, I get the exact same Exception saying it is missing the "older" version 1.0.2592.51 of the Webview package:

Could not load file or assembly 'Microsoft.Web.WebView2.Wpf, Version=1.0.2592.51, Culture=neutral, PublicKeyToken=2a8ab48044d2601e'. The system cannot find the file specified.