Why can I not use WebView2 in my .NET 8.0 WPF application?
I can load the package from NuGet, the dlls are referenced in my project:
Microsoft.Web.WebView2.CoreMicrosoft.Web.WebView2.WinFormsMicrosoft.Web.WebView2.Wpf
Those dlls are also present in the debug folder.
I added just a simple WV2 in my XAML:
<Window x:Class="webview2test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:webview2test"
xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<wv2:WebView2 Name="webView" Source="https://www.microsoft.com" />
</Grid>
</Window>
I immediately get this error:
XDG0003 Unable to load the file or assembly 'Microsoft.Web.WebView2.Wpf, Version=1.0.3351.48, Culture=neutral, PublicKeyToken=2a8ab48044d2601e'
It seems wv2:WebView2 is the source of the problem...
How can I resolve this?
EDIT to add more details
I installed the WebView2 with NuGet and I can see the Microsoft.Web.WebView2 listed in the packages folder
the csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3351.48" />
</ItemGroup>
</Project>
EDIT more details after cleaning all project errors
The error is only appearin in a Tabitem user control but don't affect the application to work
<TabItem x:Class="WpfApp1.WebBrowser"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
xmlns:web="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<web:WebView2 Name="Browser" Source="http://192.168.1.150"></web:WebView2>
</Grid>
</TabItem>
END
I didn't found any solution but at the same time that error isn't really blocking the script to run correctly, maybe a bug? Anyway I will continue like this for now and see if in the future I will get more troubles
Dependencies->Packages? -- Post the content of the.csprojfile