Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlazorWebView & WindowsAppSDK - WebView2 DLL missmatch #10121

Open
vsfeedback opened this issue Oct 30, 2024 · 3 comments
Open

BlazorWebView & WindowsAppSDK - WebView2 DLL missmatch #10121

vsfeedback opened this issue Oct 30, 2024 · 3 comments
Labels
area-NugetPackage Issue with the nuget package developer experience (e.g. build error, missing files) question

Comments

@vsfeedback
Copy link

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:

  • When removing the reference to the WindowsAppSDK the BlazorWebView can be instantiated
  • A DLL Microsoft.Web.WebView2.Wpf is not present in the binary folder, a DLL Microsoft.Web.WebView2.Core is present
  • Version 1.5 of the WindowsAppSDK does work without a problem (this is our current workaround to fallback to the old version)
  • The VisualStudio version used for compilation seems to have an impact (see below)
  • The following BlogPost states changes in the way the WebView is used in the WindowsAppSDK. Could this be related?https://blogs.windows.com/windowsdeveloper/2024/09/04/whats-new-in-windows-app-sdk-1-6/

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.

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Oct 30, 2024
@karkarl
Copy link
Contributor

karkarl commented Oct 31, 2024

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

@karkarl karkarl added area-NugetPackage Issue with the nuget package developer experience (e.g. build error, missing files) question and removed needs-triage Issue needs to be triaged by the area owners labels Oct 31, 2024
@oggy22
Copy link

oggy22 commented Nov 1, 2024

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NugetPackage Issue with the nuget package developer experience (e.g. build error, missing files) question
Projects
None yet
Development

No branches or pull requests

4 participants