如何在ExcelDNA加载项中使用Cefsharp浏览器控件? [英] How to use Cefsharp browser control in ExcelDNA add-in?

查看:256
本文介绍了如何在ExcelDNA加载项中使用Cefsharp浏览器控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ExcelDNA 创建的Excel加载项,其中包含 Cefsharp 浏览器 rel = nofollow noreferrer>自定义任务窗格。当我运行加载项时,会出现以下错误:

I creating excel add-In with ExcelDNA that contains Cefsharp browser in Custom task pane. When I run add-In, I'll get an error about:


无法加载文件或程序集 CefSharp,Version = 65.0。 0.0,
文化=中立,PublicKeyToken = 40c4b6fc221f4138或其
依赖项之一。找不到指定的模块。

Could not load file or assembly "CefSharp, Version=65.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138" or one of its dependencies. The specified module could not be found.

我该如何解决?

创建包含 ChromiumWebBrowser 的用户控件:

        [ComVisible(true)]
        public class MyBrowser : UserControl
        {
            ChromiumWebBrowser browser = new ChromiumWebBrowser("www.google.com");
            browser.Dock = DockStyle.Fill;
            this.Controls.Add(browser);
        }

用于创建自定义任务窗格的代码:

Code for creating custom task pane:

        private static void CreateCTP()
        {
            ctp = CustomTaskPaneFactory.CreateCustomTaskPane(typeof(MyBrowser), 
                            "My Custom Task Pane");
            //Setting ctp params...
            ctp.Visible = true; 
        }

注意:


  • 所有已连接的依赖项/引用和文件(非托管资源)已添加到 bin / Debug

  • 加载项正常工作(如果ChromiumWebBrowser未使用)。

  • All dependencies/references connected and files (unmanaged resources) added into bin/Debug.
  • Add-In works normaly (if ChromiumWebBrowser not using).

推荐答案

这是CefSharp的已知问题 ...它与非默认AppDomains不兼容。您可以在问题 多个AppDomains错误无法跨AppDomains传递GCHandle

Excel-DNA为每个加载项创建一个自定义/非默认AppDomain,而CefSharp则不喜欢。有人曾试图修复CefSharp不久前,但不幸的是请求pull 未被接受/合并,问题仍然存在。如果您足够勇敢,可以下载该pull-request并拥有您自己的CefSharp版本,并应用了此修复程序。

Excel-DNA creates a custom/non-default AppDomain for each add-in, and CefSharp doesn't like that. Someone tried to fix CefSharp a while ago, but unfortunately the pull-request was not accepted/merged and the problem still persists. If you're brave enough, you can download that pull-request and have your own version of CefSharp, with that fix applied.

一种将CefSharp与Excel-DNA结合使用的解决方法是在单独的过程中默认的AppDomain。操作示例此处此处

A workaround to use CefSharp as-is with Excel-DNA is to run it in separate process, in a default AppDomain. Examples of how to do it here and here.

您还可以在此讨论中阅读有关此内容的更多信息: CefSharp和ExcelDNA

You can also read more about this in this discussion: "CefSharp and ExcelDNA".

当然,鉴于这是CefSharp特有的问题,另一种替代方法是使用其他内容,例如 CefGlue ChromiumFx

Of course, given this is a CefSharp-specific problem, another alternative is to use something else instead, like CefGlue or ChromiumFx, for example.

这篇关于如何在ExcelDNA加载项中使用Cefsharp浏览器控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆