我试图在中使用CefSharp WindowForm控件。CefSharp.WinForms版本为75.1.142,我正在Excel 2013 (64位)上做一个加载项,直到2017年。
我得到了FileNotFoundException:“无法加载文件或程序集”CefSharp、Version=75.1.142.0、Culture=neutral、PublicKeyToken=40c4b6fc221f4138“或其依赖项之一。系统找不到指定的文件。关于下面的代码执行。
public void InitBrowser()
{
var cefSettings = new CefSettings();
cefSettings.MultiThreadedMessageLoop = true;
// I'm setting current directory to D:\\CEF\\cefsharp\\ExcelWinform\\ExcelWinformAddIn\\bin\\x64\\Debug\\ where all the CefSharp dlls and dependencies are present.
cefSettings.BrowserSubprocessPath = "D:\\CEF\\cefsharp\\ExcelWinform\\ExcelWinformAddIn\\bin\\x64\\Debug\\CefSharp.BrowserSubprocess.exe";
if (!Cef.Initialize(cefSettings, performDependencyCheck: true, browserProcessHandler: null))
{
throw new Exception("Unable to Initialize Cef");
}
browser = new ChromiumWebBrowser("http://www.google.com");
{
Dock = DockStyle.Fill;
}
BrowserSettings browserSettings = new BrowserSettings();
//browserSettings.FileAccessFromFileUrls = CefState.Enabled;
//browserSettings.UniversalAccessFromFileUrls = CefState.Enabled;
browserSettings.BackgroundColor = 0xFFFF00;
browserSettings.LocalStorage = CefState.Enabled;// enable Local access
browser.BrowserSettings = browserSettings;
this.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
}
If instead of VSTO Excel addin, I just create a simple WindowFrom application then the abve code is working fine.发布于 2019-09-24 10:06:25
不支持在CefSharp插件/加载项中直接使用。
如果为应用程序安装了多个VSTO外接程序,则每个VSTO外接程序将加载到不同的应用程序域中。
根据https://learn.microsoft.com/en-us/visualstudio/vsto/architecture-of-vsto-add-ins?view=vs-2019,Office VSTO将使用AppDomain来加载您的add-in (我相信,即使您只加载一个外接程序,也会使用非默认的应用程序域)。
CefSharp是使用不能在非默认AppDomain中加载的VC++构建的。您所看到的错误与插件无法加载libcef.dll有关,您可以解决此问题,只需面对Cannot pass a GCHandle across AppDomains。
您可以在进程之外运行CefSharp,这里有一个例子。这有点过时了,基本面应该仍然是相关的。请参阅https://github.com/stever/AppHostCefSharp
我个人的建议是使用基于CefGlue的P/Invoke,因此使用一种与非托管libcef.dll交互的根本不同的方法。
要获得与CefSharp兼容的VSTO的替代方案,请查看NetOffice。
另请参阅
https://stackoverflow.com/questions/58024079
复制相似问题