microsoft / microsoft/microsoft-ui-xaml
BlazorWebView & WindowsAppSDK - WebView2 DLL missmatch
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
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:
- 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
- Add a Package reference to the Microsoft.WindowsAppSDK version 1.6+
- Set the target framework of the project to at least net8.0-windows10.0.17763.0
- Run the app to provoke the error
Attached is a premade sample project to reproduce the problem:
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached BlazorWpf1 sample and its MainWindow.xaml, then run the package combination from the issue using Microsoft.WindowsAppSDK 1.6 and Microsoft.AspNetCore.Components.WebView.Wpf 8.0.92. Compare the output and runtime behavior with WindowsAppSDK 1.5, focusing on the missing Microsoft.Web.WebView2.Wpf assembly. Done means the WPF BlazorWebView instantiates without the XamlParseException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100