加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

初始化C#的geckoWebBrowser异常

发布时间:2020-12-15 21:03:58 所属栏目:百科 来源:网络整理
导读:我的程序如下引发异常. Program.cs如下: static void Main() { Gecko.Xpcom.Initialize("D:xulrunner"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } Form1.cs如下: p
我的程序如下引发异常.

Program.cs如下:

static void Main()
    {
        Gecko.Xpcom.Initialize("D:xulrunner");
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());

    }

Form1.cs如下:

private void Form1_Load(object sender,EventArgs e)
    {
        //Gecko.Xpcom.Initialize("D:xulrunner");

        geckoWebBrowser1.Navigate("http://www.google.com");

    }

翻译自中文,例外情况如下:

“System .__ ComObject”无法转换接口类型“Gecko.nsIWebNavigation”

以下代码中抛出异常:

public ChromeContext()
{
    using (var appShallSvc = Xpcom.GetService2<nsIAppShellService>(Contracts.AppShellService))
    {
        webNav = appShallSvc.Instance.CreateWindowlessBrowser(true).AsComPtr(); //this is where the exception is thrown

        webNav.Instance.LoadURI("chrome://global/content/alerts/alert.xul",null,null);

    }

}

任何帮助将不胜感激.

解决方法

对于旧版本,您需要将GeckoFX版本与xulrunner的完全正确版本相匹配.

在这里查看您的版本:https://bitbucket.org/geckofx/geckofx/wiki/Version_lists

在这里下载xulrunner:https://releases.mozilla.org/pub/xulrunner/releases/

但是版本45.0大大简化了这一点:

For Geckofx 45.0 and newer publishing has been moved to a nuget package model,which includes the both the geckofx files and the required firefox files.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读