I'm trying to learn to create an app using C# utilizing the WebView2 element. Because I'm trying to distribute this to computers that may not have Edge, I'm trying to utilize the fixed version of the Webview2 runtime. I believe I uploaded the files to the correct directories and ensured that the location for the "userDataFolder" was located in a writable file, but I'm still getting the following error message:
Microsoft.Web.WebView2.Core.WebView2RuntimeNotFoundException: 'Couldn't find a compatible Webview2 Runtime installation to host WebViews.'
I stored the files for the fixed version runtime here: C:\Users\janif\source\repos\browserPackageV1\browserPackageV1\bin\Debug\net5.0-windows\browserPackageV1.exe.WebView2\Microsoft.WebView2.FixedVersionRuntime.94.0.992.50.x86
Here's my code:
'''
public Form1()
{
InitializeComponent();
webBrowser.Source = new Uri("https://www.microsoft.com/en-us/");
InitWebView();
}
String locOfRuntime = @"\\browserPackageV1\\bin\\Debug\\net5.0-windows\\browserPackageV1.exe.WebView2";
String locOfSavedState = @"\\browserPackageV1\\bin\\Debug\\net5.0-windows\\temp";
async void InitWebView()
{
await CoreWebView2Environment.CreateAsync(
browserExecutableFolder: locOfRuntime,
userDataFolder: locOfSavedState);
}
'''
Am I missing something? Should I be directing the "browserExecutableFolder" somewhere else? Do I have the wrong file location syntax? I'm currently a student and I'm trying to teach myself how to do this, but all the documentation about this has been really fuzzy and I've come to a wall. I've seen Microsoft's documentation using "WebView2.EnsureCoreWeb2Async", and have tried that (see below):
'''
async void InitWebView()
{
await joinBrowser.EnsureCoreWebView2Async
(
Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync
(
browserExecutableFolder: locOfRuntime,
userDataFolder: locOfState,
CoreWebView2EnvironmentOptions options = null
)
);
}
'''
...but this too is not working. VS is not accepting "CoreWebView2EnvironmentOptions options = null". Can someone please help me here? I can't find anything clear-cut out there that would actually make the fixed version of WebView2 work.
Thanks!