使用 CEFSharp Web 浏览器的 WPF 应用程序在 clickonce 版本中崩溃

WPF application using CEFSharp Web Browser crashing in clickonce release

我有一个简单的 WPF 应用程序,它在调试时运行良好,但是当我尝试加载 CEFSharp 网络浏览器时单击一次释放它崩溃

我有一个登录页面,用户点击打开浏览器后,我收到以下错误

An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: The invocation of the constructor on type 'MyProject.Views.CefSharpWebBrowserUserControl' that matches the specified binding constraints threw an exception.

> <TabItem Header="Web Page" Name="CefWebPage">
>                 <Grid Background="#FFE5E5E5" Margin="0">
>                     <Grid.ColumnDefinitions>
>                         <ColumnDefinition Width="871*"/>
>                     </Grid.ColumnDefinitions>
>                     <views:CefSharpWebBrowserUserControl x:Name="CefSharpWebBrowserUserControl"></views:CefSharpWebBrowserUserControl>
>                 </Grid>
>             </TabItem>

Exception: Cannot create an instance of "CefSharpWebBrowserUserControl".

TargetInvocationException: Exceptionhas been thrown by the target of an invocation.

FileNotFoundException: Could not load file or assembly 'CefSharp.Core, Version=45.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The system cannot find the file specified.

代码隐藏

    public partial class CefSharpWebBrowserUserControl : UserControl
    {
        public CefSharpWebBrowserUserControl()
        {
            InitializeComponent();
            var settings = new CefSettings();
            settings.PackLoadingDisabled = true;
            WebBrowser = new ChromiumWebBrowser();
            WebBrowser.Address = "www.google.com";
            BrowserGrid.Children.Add(WebBrowser);
        }

        public ChromiumWebBrowser WebBrowser { get; set; }
    }
}

您介意尝试在 WebBrowser.Address 处添加 https:// 吗?

因此来自:

WebBrowser.Address = "www.google.com";

拥有:

WebBrowser.Address = "https://www.google.com";

这个 post 也可能对您有所帮助。

ClickOnce 默认不包含 CefSharp 需要的 unamanged 资源。有许多问题已经解决了这个主题。

这里有几个有用的

搜索 GitHub 项目总是一个很好的资源。 https://github.com/cefsharp/CefSharp/search?q=clickonce&type=Issues&utf8=%E2%9C%93

您还需要确保 VC++ Redist 安装在您的目标机器上。有关更多信息,请参阅 https://github.com/cefsharp/CefSharp#version-branches 您需要哪个 VC++ 版本。

一般来说,请在发布问题之前尝试搜索 GitHub/Whosebug