1

I need to write a LinqPad program that uses WebView2.

I have installed the nuget package Microsoft.Web.WebView2 version 1.0.3179.45 (latest) but I can't get the program to work.

After installing the nuget LinqPad only finds the namespace Microsot.Web.Webview2.Core

The problem is that the WebView2 class I need to use is located in either Microsoft.Web.WebView2.WinForms or Microsoft.Web.WebView2.Wpf.

How do I get LinqPad to find the missing namespaces?

1
  • 2
    Use the 1.0.2592.51 NuGet package. If you have issues with the WebView2Loader.dll, call the static CoreWebView2Environment.SetLoaderDllFolderPath() method (see the docs about it), specifying the path to the dll (not the dll file itself). Also, set the data folder, so it can be written to -- If you use the WPF version, add it to a Window + DockPanel or use PanelManager.DisplayWpfElement (yourBrowserInstance). If you use the WinForms one, just add it to a Form and set its Size (or dock it). In either case, don't just .Dump() the Control's instance Commented Apr 24 at 13:26

2 Answers 2

2

Recent versions of Microsoft.Web.WebView2 have been designed with an unconventional structure that's incompatible with LINQPad.

However, LINQPad 8.9.2 (in beta at April 2025) includes code to special-case this package so that it works correctly. You can use both the WPF and Windows Forms WebView2 controls, although I actually find the WinForms version to be more stable:

var uri = new Uri ("http://www.linqpad.net");

PanelManager.DisplayWpfElement (
   new Microsoft.Web.WebView2.Wpf.WebView2 { Source = uri });

PanelManager.DisplayControl (
   new Microsoft.Web.WebView2.WinForms.WebView2 { Source = uri });

This relies on WebView2 being installed on your machine. If you would like it to work even if WebView2 is uninstalled, you can request LINQPad's version of WebView2 as follows:

var uri = new Uri ("http://www.linqpad.net");

var env = await Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync (
    Util.BrowserEngine.GetWebView2ExecutableFolder (),
    Util.BrowserEngine.GetWebView2DataFolder ()
);

var webView2 = new Microsoft.Web.WebView2.WinForms.WebView2();
await webView2.EnsureCoreWebView2Async (env);
webView2.Source = uri;
PanelManager.DisplayControl (webView2);
Sign up to request clarification or add additional context in comments.

Comments

2

That Microsoft.Web.WebView2 Nuget libary only supports .NET Framework v4.x and you are likely using a version of LinqPad that runs the newer .NET 9.0.

Instead, download LinqPad v5 and try it again.

1 Comment

Thanks for the reply. I uninstalled v5 years ago.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.