nam
nam

Reputation: 23868

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

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?

Upvotes: 4

Views: 8038

Answers (3)

Kristina Lex
Kristina Lex

Reputation: 119

Target framework needs to be 4.7.2

Upvotes: 2

Poul Bak
Poul Bak

Reputation: 10940

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.

Upvotes: 20

RandyDosanjh
RandyDosanjh

Reputation: 16

It's System.Web in 2019.

However, if you are trying to get to WebView Class, you need to use the Windows.UI.Xaml.Controls namspace.

I can read your code and see what your trying to do and this is what is it is fro Visual Studio 2019.

Upvotes: 0

Related Questions