Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Edge WebView2 - Error: The type or namespace name 'Web' does not exist in the namespace 'Microsoft'

Tags:

c#

wpf

webview2

I'm working on this official tutorial: Getting started with WebView2 in WPF (Preview).

  1. Have installed Microsoft Edge (Chromium) Canary channel on my Windows 10 pro -ver 1903.
  2. Have created a .NET Core 3.1 - WPF project on latest version VS2019 - ver16.6.3.
  3. Have installed the Nuget package Microsoft.Web.WebView2 -Version 0.9.538.

But, per instructions in step 3 of the tutorial, when I add namespace xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf" in <Window/> tag of MainWindow.xaml, and build (F5) the app, I get the following error at line using Microsoft.Web.WebView2.Wpf; of the MainWindow.g.cs file:

Error:

Error CS0234 The type or namespace name 'Web' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

MainWindow.xaml:

<Window x:Class="WpfWebView2TEST.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:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        
    </Grid>
</Window>

Question: What may be a cause of the error and how can it be resoled?

like image 206
nam Avatar asked Dec 01 '22 09:12

nam


1 Answers

To use the WebView2 control in .Net you must use the the version, that is marked 'pre-release'.

Only that version contains the .Net librarys necessary.

It is actually mentioned (but not very clear) on the installation page.

When installing, make sure you have 'Include prerelease' checked: enter image description here

Note: After you have installed the 'pre-release' version, Visual Studio will tell you there's an update (which is the version without 'pre-release'). DO NOT UPGRADE!

Well, at some point in the future, they will of course support .Net from the standard version, but not for now.

like image 112
Poul Bak Avatar answered Dec 04 '22 23:12

Poul Bak