我刚开始的时候很难过。首先,我尝试使用NuGet包。当我安装它们时,对CefSharp DLL的任何必要引用都不会出现在我的引用列表中。因此,我通过搜索/packages子目录手动添加了它们。在让我的项目构建之后,我发现当我执行一个URL 时,什么都没有发生。没有加载网页,没有错误消息,没有触发异常。没什么。
我完全删除了CefSharp Nuget包,并从GitHub中删除了最新的回购源。我首先确保CefSharp.WinForms.Example项目的URL加载工作正常。效果很好。然后,我将必要的项目集从CefSharp解决方案复制到项目的解决方案中,直到正确构建解决方案为止。我从BrowserForm项目中添加了CefSharp.WinForms.Example表单,以确保它不是我的代码。但是,当我在运行时打开该表单时,在地址栏中输入一个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>}然而,它显然不是空的,但是它被当作是空的。(或者我对{CefRefPtr}值的分析是错误的,我的分析也是错误的。)
在这两种情况下,"if“语句将cefFrame的当前值视为等于nullptr,并跳过在cefFrame引用对象上调用LoadURL()方法的行。在GitHub CefSharp repo的解决方案和it if的副本中,我跟踪这些完全相同的代码,输入"if“块并执行LoadURL()方法。我检查了cefFrame的值,它与我的应用程序中的值相同。由于一些非常奇怪的原因,这里或者我的应用程序中有一个更隐秘的问题,或者它确实将cefFrame的值{CefRefPtr}与nullptr的值相同,而它不应该这样做。
如果有人知道我如何在代码中工作,我会非常感激的。
更新:我进行了三次检查,构建配置在工作的GitHub CefSharp解决方案和不起作用的项目之间是相同的。除了将核心项目设置为Win32之外,一切都设置为x86 (在这两种情况下都是如此)。
我刚刚进行了重新构建,在此基础上,我遍历了每个包含的项目,并手动完全删除了/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项目的引用来重新添加它。但我还是得到了例外。
发布于 2015-01-18 02:16:33
好了,我要跑了。尽管使用的是完整的源代码而不是NuGet包。我发现我需要做几件事:
根据常见问题:
- libcef.dll
- icudtl.dat
- CefSharp.dll
- CefSharp.WinForms.dll
注意,最好将日志文件详细设置为详细,这样您就可以看到日志文件中的任何错误。他们可以成为救星。
https://stackoverflow.com/questions/28004316
复制相似问题