I created a new .net 8.0 winforms project in vs2022, it includes the latest webview2 nuget package.
This is the full project code:
myawesomeprogram.cs
namespace myawesomenamespace
{
internal static class myawesomeprogram
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new myawesomeform());
}
}
}
myawesomeform.designer.cs
namespace myawesomenamespace
{
partial class myawesomeform
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
myawesomewebview = new Microsoft.Web.WebView2.WinForms.WebView2();
((System.ComponentModel.ISupportInitialize)myawesomewebview).BeginInit();
SuspendLayout();
myawesomewebview.AllowExternalDrop = true;
myawesomewebview.CreationProperties = null;
myawesomewebview.DefaultBackgroundColor = Color.White;
myawesomewebview.Dock = DockStyle.Fill;
myawesomewebview.Location = new Point(0, 0);
myawesomewebview.Name = "myawesomewebview";
myawesomewebview.Size = new Size(800, 450);
myawesomewebview.TabIndex = 4;
myawesomewebview.ZoomFactor = 1D;
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(myawesomewebview);
Name = "myawesomeform";
Text = "myawesomeform";
WindowState = FormWindowState.Maximized;
Load += myawesomeform_Load;
((System.ComponentModel.ISupportInitialize)myawesomewebview).EndInit();
ResumeLayout(false);
}
private Microsoft.Web.WebView2.WinForms.WebView2 myawesomewebview;
}
}
myawesomeform.cs
using Microsoft.Web.WebView2.Core;
namespace myawesomenamespace
{
public partial class myawesomeform : Form
{
private Random? myawesomerandom;
public myawesomeform()
{
InitializeComponent();
}
private async void myawesomeform_Load(object sender, EventArgs e)
{
CoreWebView2Environment? myawesomeenvironment = await CoreWebView2Environment.CreateAsync();
await myawesomewebview.EnsureCoreWebView2Async(myawesomeenvironment);
myawesomerandom = new Random();
await Task.Delay(myawesomerandom.Next(1000, 2000));
myawesomewebview.Source = new Uri("http://lixxx.co.uk");
await Task.Delay(myawesomerandom.Next(1000, 2000));
myawesomewebview.Source = new Uri("http://lmfgtfy.co.uk");
}
}
}
It runs on my development machine perfectly well.
I configured a publish profile with a release configuration, a .net 8.0 windows target framework, a win x64 target runtime, a self contained deployment mode using the single file and ready to run compilation options.
The published .exe file, in its published directory, runs correctly.
When I cut and paste the entire published directory onto a 64 bit AMD server, running windows server 2022 and run the .exe, the application loads and immediately displays an unhandled error exception dialogue with the exception text:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.IO.FileNotFoundException: The system cannot find the file specified. (0x80070002)
************** Loaded Assemblies **************
System.Private.CoreLib
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Private.CoreLib.dll
----------------------------------------
myawesomeproject
Assembly Version: 1.0.0.0
Location:
----------------------------------------
System.Runtime
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Runtime.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App8.0.7System.Windows.Forms.dll
----------------------------------------
System.ComponentModel.Primitives
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.ComponentModel.Primitives.dll
----------------------------------------
System.Windows.Forms.Primitives
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App8.0.7System.Windows.Forms.Primitives.dll
----------------------------------------
System.Drawing.Primitives
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Drawing.Primitives.dll
----------------------------------------
System.Collections.Specialized
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Collections.Specialized.dll
----------------------------------------
System.Runtime.InteropServices
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Runtime.InteropServices.dll
----------------------------------------
System.Threading
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Threading.dll
----------------------------------------
System.Diagnostics.TraceSource
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Diagnostics.TraceSource.dll
----------------------------------------
System.Collections
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Collections.dll
----------------------------------------
System.Drawing.Common
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App8.0.7System.Drawing.Common.dll
----------------------------------------
Microsoft.Win32.Primitives
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7Microsoft.Win32.Primitives.dll
----------------------------------------
System.ComponentModel.EventBasedAsync
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.ComponentModel.EventBasedAsync.dll
----------------------------------------
System.Threading.Thread
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Threading.Thread.dll
----------------------------------------
Accessibility
Assembly Version: 4.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App8.0.7Accessibility.dll
----------------------------------------
Microsoft.Web.WebView2.WinForms
Assembly Version: 1.0.2592.51
Location:
----------------------------------------
Microsoft.Web.WebView2.Core
Assembly Version: 1.0.2592.51
Location:
----------------------------------------
mscorlib
Assembly Version: 4.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7mscorlib.dll
----------------------------------------
System.ComponentModel.TypeConverter
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.ComponentModel.TypeConverter.dll
----------------------------------------
System.ComponentModel
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.ComponentModel.dll
----------------------------------------
System.Numerics.Vectors
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Numerics.Vectors.dll
----------------------------------------
System.Private.Uri
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Private.Uri.dll
----------------------------------------
Microsoft.Win32.SystemEvents
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App8.0.7Microsoft.Win32.SystemEvents.dll
----------------------------------------
System.Memory
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Memory.dll
----------------------------------------
System.Collections.NonGeneric
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Collections.NonGeneric.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.dll
----------------------------------------
System.Threading.ThreadPool
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Threading.ThreadPool.dll
----------------------------------------
System.Runtime.Loader
Assembly Version: 8.0.0.0
Location: C:Program FilesdotnetsharedMicrosoft.NETCore.App8.0.7System.Runtime.Loader.dll
----------------------------------------
************** JIT Debugging **************
The application had a requirement to write to a text file, but I have since deleted it from the latest builds.
The server has the .net 8.0 hosting bundle and the .net 8.0 x64 desktop runtime installed.