【发布时间】:2015-01-17 21:06:53
【问题描述】:
我正在艰难地开始它。首先,我尝试使用 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 并跳过调用 LoadURL()cefFrame 引用对象上的 /em> 方法。我在我的 GitHub CefSharp 存储库的解决方案副本中跟踪了完全相同的代码,它确实进入了“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 项目的引用来重新添加它。但我仍然得到那个例外。
【问题讨论】:
标签: c# c++ chromium cefsharp nullptr