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

问题描述

我使用创建的Excel加载项,其中包含浏览器 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:

我该如何解决?

创建包含 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).

推荐答案

...它与非默认AppDomains不兼容。您可以在问题 ,但不幸的是请求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.

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

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

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

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浏览器控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 16:10