首页 文章

任何CPU的CefSharp都无法显示浏览器

提问于
浏览
1

首先,我是.NET和C#的新手,这是一个同时学习C#和CEF的项目 .

我已经从网上学到了很多教程,并查看了CefSharp示例来创建WinForms应用程序 .

我从NuGet安装了CefSharp.WinForms 53.0.1,我的项目使用Any CPU(CefSharp 51有任何CPU支持) .

为实现这一目标,我主要遵循Ourcode(http://ourcodeworld.com/articles/read/173/how-to-use-cefsharp-chromium-embedded-framework-csharp-in-a-winforms-application)的教程 . 我根据建议对任何CPU进行了更改,并包含了加载谷歌的基本代码 .

一切都很好,但是当表单显示时没有显示浏览器,只是一个空白表单 .

如果我将目标设置为x64或x86,则浏览器将按预期显示 .

我在Ourcode评论中注意到用户Edek Halon遇到了同样的问题,但似乎没有提供任何解决方案 . Edek和我有相同的设置,所以我想知道这是否是53.0.1中的一个问题? Potentialy Joey De Vries在评论中有同样的问题 .

此GitHub问题中包含对CefSharp中Any CPU的支持:https://github.com/cefsharp/CefSharp/issues/1714

CefSharp(https://github.com/cefsharp/CefSharp/wiki/Trouble-Shooting)有一个故障排除页面,看起来有点矛盾 . 在常规故障排除下

1)平台目标使用NuGet包时,您必须选择x86或x64 . 如果您选择AnyCPU,NuGet魔法将无法正常工作 .

是否需要从任何CPU的源代码构建CefSharp?

1 回答

  • 0

    如果有人遇到此问题,请按照以下链接访问Github教程:https://github.com/cefsharp/CefSharp/issues/1714

    基本上代码应该如下(Winforms示例):

    CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
     Cef.EnableHighDPISupport();
     CefSettings settings = new CefSettings
            {
                CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"), //By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
                BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe"
            };
            Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null); // Initialize cef with the provided settings            
            chromeBrowser = new ChromiumWebBrowser("http://ourcodeworld.com"); // Create a browser component            
            this.Controls.Add(chromeBrowser); // Add it to the form and fill it to the form window.
            chromeBrowser.Dock = DockStyle.Fill;
    

相关问题