gpt4 book ai didi

c# - 为 C# 初始化 geckoWebBrowser 异常

转载 作者:行者123 更新时间:2023-11-30 12:56:26 33 4
gpt4 key购买 nike

我下面的程序抛出异常。

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”无法转换接口(interface)类型“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# - 为 C# 初始化 geckoWebBrowser 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40971223/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com