CEF - Embedded Chromium - C# Windows 窗体无法在另一台计算机上运行



我创建了一个名为"WindowsFormsApp2"的空窗口表单应用程序。 我在其中添加了以下Nuget包:

Microsoft.Toolkit.Forms.UI.Controls.WebView.5.1.1

休息夏普.106.6.10

CefSharp.WinForms.73.1.130

后一个包添加了以下附加包:

头孢夏普.通用.73.1.130

cef.redist.x64.73.1.13

cef.redist.x86.73.1.13

我的app.config是(有效地启用了系统诊断跟踪(:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <trace autoflush="true">
      <listeners>
        <add name="log" type="System.Diagnostics.TextWriterTraceListener" initializeData="output.log" />
      </listeners>
    </trace>
  </system.diagnostics>
  <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
  </startup>
</configuration>

然后,我将以下代码添加到窗体中:

public partial class Form1 : Form {
    private ChromiumWebBrowser chromeWebBrowser = null;
    public Form1() {
        try {
            Debug.WriteLine("Got here0");
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
            Debug.WriteLine("Got here1");
            InitializeComponent();
            Debug.WriteLine("Got here2");
            Cef.Initialize(new CefSettings());
            Debug.WriteLine("Got here3");
            this.chromeWebBrowser = new ChromiumWebBrowser("");
            Debug.WriteLine("Got here4");
            this.Controls.Add(chromeWebBrowser);
            Debug.WriteLine("Got here5");
            this.chromeWebBrowser.Dock = DockStyle.None;
            Debug.WriteLine("Got here6");
            this.chromeWebBrowser.Height = Screen.GetWorkingArea(this).Height;
            Debug.WriteLine("Got here7");
            this.chromeWebBrowser.Width = Screen.GetWorkingArea(this).Width;
            Debug.WriteLine("Got here8");
            this.chromeWebBrowser.Load("https://www.google.com");
            Debug.WriteLine("Got here9");
        } catch (Exception e) {
            Debug.WriteLine("Exception: " + e.ToString());
        } // try catch
    }
    static void MyHandler(object sender, UnhandledExceptionEventArgs args) {
        Exception e = (Exception)args.ExceptionObject;
        Debug.WriteLine("Unhandled Exception: " + e.ToString());
    }
}

我在编译机上编译并运行表单没有问题。 它将输出写入调试视图应用程序,并创建输出.log文件。 它会打开窗体,并在浏览器中显示 www.google.com。

我有一个全新的虚拟机,其中包含最新的Windows 10更新,包括.Net Framework 4.8。 我将构建目录的内容逐字复制到新 VM,当我运行 EXE 时,没有视觉证据表明它运行了。 "调试视图"窗口中没有条目,输出.log文件中也没有条目。 它运行的唯一证据是 3 个新窗口的事件应用程序日志。

错误 - 事件 ID 1026:

Application: WindowsFormsApp2.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at WindowsFormsApp2.Form1..ctor()
   at WindowsFormsApp2.Program.Main()

错误 - 事件 ID 1000

Faulting application name: WindowsFormsApp2.exe, version: 1.0.0.0, time stamp: 0xa390557a
Faulting module name: KERNELBASE.dll, version: 10.0.18362.267, time stamp: 0xf09944f9
Exception code: 0xe0434352
Fault offset: 0x000000000003a839
Faulting process id: 0x1c08
Faulting application start time: 0x01d54c7eda2259ba
Faulting application path: C:TempFormAppWindowsFormsApp2.exe
Faulting module path: C:WINDOWSSystem32KERNELBASE.dll
Report Id: 181886c1-19f4-4931-91b1-95af1e001fec
Faulting package full name: 
Faulting package-relative application ID: 

信息 - 事件 ID 1001:

Fault bucket 1306785398527647396, type 5
Event Name: CLR20r3
Response: Not available
Cab Id: 0
Problem signature:
P1: WindowsFormsApp2.exe
P2: 1.0.0.0
P3: a390557a
P4: WindowsFormsApp2
P5: 1.0.0.0
P6: a390557a
P7: 5
P8: 13
P9: System.IO.FileNotFoundException
P10: 
Attached files:
\?C:ProgramDataMicrosoftWindowsWERTempWER2DBB.tmp.dmp
\?C:ProgramDataMicrosoftWindowsWERTempWER2E58.tmp.WERInternalMetadata.xml
\?C:ProgramDataMicrosoftWindowsWERTempWER2E69.tmp.xml
\?C:ProgramDataMicrosoftWindowsWERTempWER2E67.tmp.csv
\?C:ProgramDataMicrosoftWindowsWERTempWER2E87.tmp.txt
These files may be available here:
\?C:ProgramDataMicrosoftWindowsWERReportArchiveAppCrash_WindowsFormsApp2_10eb50ab8221721592a26845885856a298fbc16_4defeb0e_c2d699e3-92a1-4aa8-9edd-0573661e017d
Analysis symbol: 
Rechecking for solution: 0
Report Id: 181886c1-19f4-4931-91b1-95af1e001fec
Report Status: 268435456
Hashed bucket: bb3bca32b533c2a00222a26574e85ea4
Cab Guid: 0

如果我从表单中删除对 CEF 的引用,则表单在两台计算机上都可以打开而不会出现问题。 显然,CEF 包引用了一些未放在构建目录中的文件,但我不确定如何找出它是什么。

有什么想法吗?

谢谢一堆。

CEF 依赖于 Microsoft Visual C++ 2015 Redistributable。 不知何故错过了这个要求。

最新更新