编程语言
首页 > 编程语言> > 初始化C#的geckoWebBrowser异常

初始化C#的geckoWebBrowser异常

作者:互联网

我的程序如下引发异常.

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", 0, null, 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.

标签:c,geckofx
来源: https://codeday.me/bug/20190710/1429098.html