首页 > 代码库 > CefSharp使用记录

CefSharp使用记录

webbrowser的诟病做开发的都知道,这次的发开项目中我就直接使用了CefSharp组件,过程也是一波三折,遇到很多问题,现在这块基本没什么问题了,过来做下记录。

1.下载地址:https://github.com/cefsharp/CefSharp/

2.之前一直用的vs2010,办公机器懒得折腾一直没装新版vs,无奈打不开这个程序,安装了vs2015 专业版

3.源码调试运行都很顺利

4.项目引用,开发环境基本也没什么大问题。

5.组件引用后,发现关闭程序时出现卡死,后来在FormClosed事件里各种资源释放还是无解,最后研究了下程序退出的各种方法,把Environment.Exit(0);换成Application.Exit();居然完美解决?! 还是不太懂原理,现在依然觉得好神奇。。。。有大神看到的话还请不吝指教~~

6.后来发布的时候的发现在别人的机器上无法运行,提示报错:

System.IO.FileNotFoundException: Could not load file or assembly ‘CefSharp.Core.dll‘ or one of its dependencies. 找不到指定的模块。
File name: ‘CefSharp.Core.dll‘

百度了一下,万幸找到官网帮助:

https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#Runtime_dependencies

引用第4个高频问题如下:

4. Why do I get an error about "Could not load file or assembly ‘CefSharp.Core.dll‘ or one of its dependencies. The specified module could not be found." when trying to run my CefSharp-based application? It compiles successfully, but does not run? It runs on my developer machine, though throws an exception when I copy it to another computer?

This is a common error, typically one of the following

  1. VC++ 2012/2013 Redistributable Package is required in order to run CefSharp on non developer machines. See FAQ #6 below for more information. You can include the required dlls as part of your application.
  2. Not all dependencies are present in the executing folder. CefSharp includes unmanaged dll‘s and resources, these are copied to the executing folder via two .props file which are included in your project when you install the Nuget packages. See list of required files below, make sure the required files are present.
  3. You packaged your application for distribution via an installer and it doesn‘t run on the target machine. Installers don‘t include the unmanaged resources by default, you‘ll need to add them manually. For ClickOnce, see #1314 for some pointers and solutions other users have come up with.
  • 可以先先检查下必要文件是否缺失,下面链接可以查看,如果文件没有问题,查看是否没有安装相应VC++组件。之前一直被一些文章误导说要安装与你vs版本相同的vc++插件版本,于是先安装了VC++2015,依然报错,然后按别人的提示也安装了VC++2012,依然报错,后来看到这个解答才知道我的CefSharp用的是47版本,只需安装VC++2013版本就好了,后来问题完美解决。

A list of required files can be found here: Output files description (Redistribution)

NOTE: This also applies if you get a FileNotFoundException when initializing the WPF control in XAML.

NOTE 2: If compiling from source (not recommended, use the Nuget packages) and you notice that you can no longer build in debug mode, but release builds work just fine you may need to repair your version of Visual Studio. This happens in rare cases where you will get the same exact message as a missing unmanaged .dll file as shown above.

https://github.com/cefsharp/CefSharp/wiki/Output-files-description-table-(Redistribution)

Visual C++

For versions 43 and above you will need Visual C++ Redistributable Packages for Visual Studio 2013

For versions 41 and below you will need Visual C++ Redistributable for Visual Studio 2012 Update 4.

VC++ is distributed in both x86 and x64 variants, make sure you install the version matching your target architecture. (i.e. when targeting x86, x86 redistributable packages are needed).

 

CefSharp使用记录