Working on C# XAML Windows Application with CefSharp and its ChromiumWebBrowser for a document viewer. The project builds fine without error but whenever I try to open/view an image on the application using Chromium, an error pops up that:
System.Windows.Markup.XamlParseException: The invocation of constructor on type CefSharp.Wpf.ChromiumWebBrowser that matches the specified binding constraints threw an exception
Inner Exception: FileNotFoundException: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies
CefSharp.Common package is installed in the project, so is the CefSharp.Wpf package and I have also added the references to the project.
Here is my ChromeControl.xaml:
<UserControl x:Class="Viewer.Chrome.ChromeControl">
<-- namespaces defined here -->
<Grid>
<chrome:ChromiumWebBrowser Name="viewer" RenderOptions.BitmapScalingMode="HighQuality" TextOptions.TextRenderingMode="ClearType" />
</Grid>
</UserControl>
Here is my ChromeControl.xaml.cs in the Viewer.Chrome namespace:
public partial class ChromeControl : UserControl {
public ChromeControl(ViewerWindow viewerWindow) {
InitializeComponent();
viewer.RegisterJsObject("chrome", new ChromeDomHelper(viewerWindow, viewer));
viewer.MenuHandler = new ChromeContextMenu();
}
public ChromiumWebBrowser Viewer { get { return viewer; } }
}
and I have found out that in the stack trace that it begins from in my Document Viewer.xaml.cs:
ChromeControl chrome = new ChromeControl(viewerWindow);
Have searched around a lot of ways to fix this but none seem to work in my case, any help would be greatly appreciated.
So after struggling with this for so long, I have finally fixed it. Quite a silly mistake, I was missing a few files at the installation path needed that are also specified at the link:
Output files description table (Redistribution)
I had asked another question on SO regarding a WiX installer and basically after having all the files in the installation path, I was able to debug this and get it to work.
Link to my other question (WiX):
WiX installer project: CefSharp.Core.dll could not be loaded, file not found
Update
If your project is Targeting the .NET Framework 4.5, then you have to change the .NET framework of the project to 4.6
Nuget.Config
to the Solution (not to any project)Add the following content to this file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://nuget.org/api/v2/" />
<add key="cefsharp-myget" value="https://www.myget.org/F/cefsharp/" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
3.try now.
Original Answer
I faced this exception before, I think you need to call the Initialize
method, as I remember.
using CefSharp;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Cef.Initialize();
}
See this FAQ it would be helpful.
I will summarize it here
- 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
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. 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. 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. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With