可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm trying to use CefSharp to load my web app into winfoms. I've added 2 dll files: CefSharp.dll and CefSharp.WinForms into references and add 2 dll files icudt.dll and libcef.dll into my project through add existing items.
and this is the code from the form
public WebView web_view; public Form1() { InitializeComponent(); web_view = new WebView("http://localhost:8084/wsmill",new CefSharp.BrowserSettings()); web_view.Dock = DockStyle.Fill; toolStripContainer1.ContentPanel.Controls.Add(web_view); CefSharp.CEF.Initialize(new Settings()); }
When run the app, I got this error
An unhandled exception of type 'System.IO.FileLoadException' occurred in WindowsFormsApplication1.exe Additional information: Could not load file or assembly 'CefSharp.dll' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
So anyone who know about this please help me, thanks
回答1:
You need to put these files
libcef.dll icudtl.dat CefSharp.dll CefSharp.WinForms.dll
into your bin\Debug (or bin\Release base on your configuration)
And please do not forget to install Visual C++ 2012 Redistribution ( Visual C++ 2013 Redistributable since version 43), if you don't Visual Studio will always display an exception tell not found CefSharp.dll although you already have it!
Hope this help.
回答2:
This is a common problem and is therefore mentioned in the FAQ, question number 3.
@AcccessDenied is right. The files need to be present in your output folder (bin\Debug or bin\Release). One way to make this is by using a Post-Build
action, which can set under the project settings in Visual Studio.
You can also set up the post-build in the .csproj
file, somewhat like this:
(This example is taken from the CefSharp.Wpf.Example project in the CefSharp source code, CefSharp3 branch. The exact file locations may vary in your case, especially if using CefSharp1, so adapt it as needed to ensure the files get copied correctly.)
I don't recommend putting stuff in bin\Debug or bin\Release and adding it to the solution using Copy Always
. It feels like a kludge to me.
回答3:
I have just had problems with this as well and I did the following:
CefSharp.DependencyChecker
did not report anything missing but as soon as I called new CefSharp.Wpf.ChromiumWebBrowser()
the exception occured.
I checked all ms.net CEF dlls using ILSpy and found that some of these DLLs were also located in the GAC. As soon as I removed them from GAC all worked ok!
回答4:
This is a common error which is caused by not all files being present in the output directory (bin\Debug or bin\Release, depending on which configuration you are running in Visual Studio). CefSharp.dll
is a .NET-based DLL which is dependent on other .dll files, which in turn depends further on other .dll and other files...
Here is a listing of the minimum required files:
- libcef.dll (The core Chromium DLL, which basically contains the web browser + the CEF embeddability interface which we depend on)
- icudt.dll (Unicode DLL for Chromium, must also be present)
- CefSharp.dll (managed .NET assembly which contains the core CefSharp functionality)
- CefSharp.WinForms.dll OR CefSharp.WPF.dll (depending on your project type)
Check this link for more details
回答5:
You have to set the 'copy to output' properties of the files to 'copy always' or 'copy if newer'. This copies all the files to the output directory, as stated by Coder.
回答6:
Setting "msvcp120.dll" and "msvcr120.dll" to "Copy Always" helped me.