在C# .Net 4.7.2WPF项目中,我从UserControl加载GeckoWebBrowser组件。我使用的是nuget包id="Geckofx60.64“version="60.0.18”。
我的解决方案和项目在VS2017中配置了“任何CPU”。
为了获得Firefox64存储库,我添加了nuget包id="Geckofx60.64.Windows“version="0.7.0”。
一切正常,然后我用以下代码调用一个"index.html“页面
public partial class Simulator : UserControl
{
readonly string indexPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", "index.html");
private GeckoWebBrowser _browser;
public Simulator()
{
InitializeComponent();
Xpcom.Initialize("Firefox64");
var host = new WindowsFormsHost();
_browser = new GeckoWebBrowser();
host.Child = _browser;
GridWeb.Children.Add(host);
}
private void Datacontext_ConfigurationChanged(object sender, System.EventArgs e)
{
Dispatcher.Invoke(() =>
_browser.Navigate(indexPath)
);
}
private void Simulator_OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var datacontext = DataContext as ServicesViewModel;
if (datacontext != null)
{
datacontext.ConfigurationChanged -= Datacontext_ConfigurationChanged;
datacontext.ConfigurationChanged += Datacontext_ConfigurationChanged;
}
}
}我的应用程序中的逻辑是,每当我在本地对象中有一些更改时,都刷新浏览器。
每次更改都会调用Datacontext_ConfigurationChanged。
它工作得很好,除了我可以在刷新期间随机接收到这个异常
"System.AccessViolationException: Attempted to read or write protected memory.."这个异常会导致我的应用程序崩溃,而我找不到任何解决这个异常的方法。感谢您的帮助!
发布于 2018-11-23 23:46:30
我改成了Geckofx45.64,现在没问题了..
https://stackoverflow.com/questions/53303342
复制相似问题