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).

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM