我有一个粗略的开始。首先,我尝试使用 NuGet 包。当我安装它们时,对CefSharp DLL的必要引用都没有出现在我的引用列表中。所以我通过搜索/packages子目录手动添加了它们。在构建我的项目后,我发现当我执行 URL 加载时什么也没发生。没有加载网页,没有错误消息,没有触发异常。没有什么。
我完全删除了CefSharp Nuget 包,并从 GitHub 下载了最新的 repo 源。我首先确保 CefSharp.WinForms.Example 项目中的 URL 加载工作正常。效果很好。然后,我将 CefSharp 解决方案中的必要项目集复制到我的项目解决方案中,直到我的解决方案正确构建。我从CefSharp.WinForms.Example项目中添加了 BrowserForm 表单,以确保它不是我的代码。但是,当我在运行时打开该表单时,在地址栏中输入一个 URL,然后单击Go按钮没有任何反应。就像从前一样。
我追踪了代码并在ManagedCefBrowserAdapter.h中找到了这个 C++ 方法的故障点:
void LoadUrl(String^ address)
{
_address = address;
auto cefFrame = _renderClientAdapter->TryGetCefMainFrame();
// This is where cefFrame is treated qual to nullptr despite
// having the value of {CefRefPtr<CefFrame>}, thereby defeating
// the call to LoadURL().
if (cefFrame != nullptr)
{
cefFrame->LoadURL(StringUtils::ToNative(address));
}
}
事实证明,有一个非常奇怪的问题。当我将代码跟踪到“if”语句时,我看到cefFrame的值是:
{CefRefPtr<CefFrame>}
但是,它显然不是 NULL,但它却被认为是。(或者我对 {CefRefPtr} 值的分析是错误的,我的分析也是如此。)
在任何一种情况下,“if”语句都将cefFrame的当前值视为等于nullptr并跳过调用cefFrame引用对象的LoadURL()方法的行。在我的 GitHub CefSharp repo 解决方案副本中,我跟踪了完全相同的代码,它确实进入了“if”块并执行了LoadURL()方法。我检查了 cefFrame 的值,它与我的应用程序中的值相同。由于某些真正奇怪的原因,这里或我的应用程序中存在更隐蔽的问题,或者它确实将cefFrame的 {CefRefPtr}值视为相同nullptr不应该的时候。
如果有人对我如何在我的代码中工作有任何想法,我将不胜感激。
更新:我三重检查并且构建配置在 GitHub CefSharp 解决方案和我的项目之间是相同的。一切都设置为 x86,除了设置为 Win32 的核心项目(在这两种情况下)。
我刚刚进行了重建,除此之外,我浏览了每个包含的项目,并完全手动删除了 /bin 和 /obj 目录。现在,当我运行该项目时,正在发生一些不同的事情。每当我的代码尝试创建一个新的 BrowserTabUserControl 时,我都会得到一个未处理的异常:
System.IO.FileNotFoundException was unhandled
_HResult=-2147024770
_message=Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.
HResult=-2147024770
IsTransient=false
Message=Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.
Source=HiveMind3D_proto
FileName=CefSharp.Core.dll
FusionLog=""
StackTrace:
at HiveMind3D_proto.BrowserTabUserControl..ctor(String url)
at HiveMind3D_proto.BrowserForm.AddTab(String url, Nullable`1 insertIndex) in c:\Users\Robert\Documents\Visual Studio 2012\Projects\Windows Forms\HiveMind3D_proto\HiveMind3D_proto\BrowserForm.cs:line 35
at HiveMind3D_proto.BrowserForm..ctor() in c:\Users\Robert\Documents\Visual Studio 2012\Projects\Windows Forms\HiveMind3D_proto\HiveMind3D_proto\BrowserForm.cs:line 24
at HiveMind3D_proto.Program.Main() in c:\Users\Robert\Documents\Visual Studio 2012\Projects\Windows Forms\HiveMind3D_proto\HiveMind3D_proto\Program.cs:line 26
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
我尝试在主项目中删除 CefSharp.Core 项目引用,并通过重新添加对 CefSharp.Core 项目的引用来重新添加它。但我仍然得到那个例外。