CefSharp - Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies
Asked Answered
R

7

24

I've been working on a CefSharp WinForms app for a few weeks and I've had no issues with it. This morning, while adding a few things to the application, I tried to run it to test something and got the below error:

System.IO.FileNotFoundException was unhandled Message: An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll Additional information: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.

After searching for a while I found this:

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

I checked bin/Debug/x86 for the project and all of the dependencies appear to be present. More importantly, it had been working fine five minutes earlier, and I didn't touch anything beyond a single class for an Entity Framework migration.

I've tried cleaning and rebuilding the solution, restarting Visual Studio, restarting my PC, and clearing out /bin/Debug, and none of these have helped.

Why would this error appear now after several days without it, and how can I resolve the issue?

Edit: I've done some further experimenting and I'm able to get the application to run in Release mode but not Debug mode. If I change the output path of Release mode to Debug, it fails with the same error (likewise, it succeeds in Debug with the Release output path).

Rhearheba answered 21/2, 2017 at 11:12 Comment(0)
A
23

First, make sure you installed the Microsoft Visual C++ Redistributable:

  • Version v93 and above: use Microsoft Visual C++ 2019 Redistributable or greater
  • Version v65 - v92: use Microsoft Visual C++ 2015 Redistributable or greater
  • Older Versions: use Microsoft Visual C++ 2013 Redistributable (exact version)

You could download the Visual C++ Redistributable from Microsoft. See C++ binary compatibility between Visual Studio versions for more detail on the version compatability.

Make sure to match the correct architecture, if your application is x64, you need to install the x64 build of Visual C++ Redistributable. Likewise if your application is x86 then you need to install the x86 build of Visual C++ Redistributable.

The Microsoft Visual C++ Redistributable depends on the Universal CRT. The Universal CRT is included as part of Windows 10/11. On older versions of Windows the Visual C++ Redistributable will install the Universal CRT.

For those wishing to include the Visual C++ Runtime with their application it's technically possible to include the runtime with your application. See also Local Deployment section of the Deployment in Visual C++ article from Microsoft.

Aciculum answered 10/1, 2019 at 10:41 Comment(3)
If you installed the correct VCRedist then you shouldn't need anything related to the Universal CRT. Read the Distributing Software that uses the Universal CRT section of blogs.msdn.microsoft.com/vcblog/2015/03/03/…Hartnett
VC++ 2015 Redist install fixed it for me.Nonresident
I use window server 2016, but it is not wokingUnassuming
R
12

I had the same problem until I installed the following redistributable: Microsoft Visual C++ Redistributable

Redtop answered 15/7, 2020 at 11:23 Comment(4)
I've had this error, when the client has Microsft Visual C++ 2015 Redistributable (x86) After uninstalling Microsft Visual C++ 2015 Redistributable (x86), and then installing Microsft Visual C++ 2015-2019 Redistributable (x86) - 14.28.29325 version, resolved the error similar to the topic's, as the following exception: System.BadImageFormatException: Failed to load the file 'CefSharp.Core.dll' or its integrated code or one of its dependencies. is not a valid Win32 application. (HRESULT returned exception: 0x800700C1)Ries
@Ries yes, I bumped into that as well, the thing is that version is not easy to find though :(Redtop
yeap, it was a nightmare for 2 weeks. Thanks for the info.Ries
completely understand, this made me cry tears of bloodRedtop
M
10

SuperBerry's solution of installing VC++ redistribution package solved the problem for me. I'll just provide a little troubleshooting insights from my naïve perspective.

The error message is pretty clear, either the assemble CefSharp.Core.dll is missing or one of it's dependencies. So the question boils down to how do you figure out what is missing?

So first, do you have CefSharp.Core.dll? In the Solution Explorer look at the references for the project that is having this problem. You should find a reference to CefSharp.Core. If you can't find one, you're missing that assembly. If you have one, then the problem is that you're missing one of its required dependencies. When you click on the CefSharp.Core reference, in the detail, you'll get the full path to where it's located. In my case, it was in located at 'C:\Users\tom\source\repos\MyProject\src\packages\CefSharp.Common.41.0.0\CefSharp\x86\CefSharp.Core.dll'.

You then need to get a list of the CefSharp.Core dependencies to figure out which dependency your missing. Dumpbin.exe is a command line tool that you can use to get a list of dependencies. In order to use dumpbin, you need to make sure that it can be found on the path in your system environment variables. I found on the path of the VC Tools bin directory. In my case, I found one at: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\Hostx64\x64'. Open a Command Prompt terminal and navigate to the folder containing CefSharp.Core.dll and key in the following:

 >dumpbin /dependents CefSharp.Core.dll

the result I got was:

 Dump of file CefSharp.Core.dll

 File Type: DLL

   Image has the following dependencies:

KERNEL32.dll
MSVCP110.dll
MSVCR110.dll
libcef.dll
USER32.dll
mscoree.dll

Not having worked with Microsoft Visual Studio for a number of years, I had to try and figure out where those dependencies are suppose to be located so that they can be resolved. I simply did an internet search such as "where is Kernel32.dll located" doing that for each dll until I found the missing dll. In my case, I could not find MSVCR110.dll, so I strongly suspected that was my problem. I then did an internet search for "MSVCR110.dll is missing" and found out that it was part of the vc++ redistribution. (SuperBerry, you were right on your first point). I also found that it could be downloaded from: 'https://www.microsoft.com/en-us/download/details.aspx?id=30679'. I downloaded both the x86 and x64 versions (although I only needed the x86 version for this project). They are executables that when run installs them. After installing them I found a copy of it in 'C:\Windows\SysWOW64' and in 'C:/Windows\System32'. And low and behold this problem was resolved.

What I learned from this process, was that it was difficult to know whether you have the right VC++ redistribution package installed or not. I thought I would have been installed when visual studio was installed with the VC++ features enabled. I'm using visual studio community version 2019. The project I am working with was a project I cloned from a GitHub source. I'm still confused about VC++ redistribution versioning. For example, could I have installed some later version and would it have worked (i.e. backward compatibility)?

Mcgruder answered 10/4, 2020 at 1:18 Comment(5)
See learn.microsoft.com/en-us/cpp/porting/… In general it's best to ask a new question rather than ask one in an answer.Hartnett
That document was helpful in making me understand what was going on. I cloned a GitHub project that targeted .netframework 4.0. When I cloned the project I was probably offered the chance to target a later version and I thought it would make it easier on me to just leave it a the version it was targeted for. By targeting version 4.0 that's what got the project to have a dependency on vc++ redistributable VS 2012, which I did not have installed. Had I let the project migrate to the current .framework this problem wouldn't have happened since I did have the current vc++ redist installed.Mcgruder
The CefSharp version dictates the required version of vc++. The project you cloned is using a 5 year old version. See github.com/cefsharp/CefSharp/releases and github.com/cefsharp/CefSharp#release-branchesHartnett
github.com/cefsharp/CefSharp.MinimalExample is always kept up to date and can be used to test the latest release.Hartnett
thanks amaitland, your right. I never looked to see what CefSharp was all about. I thought it was a reference that got automatically added to the project when it was created, and with that false assumption I thought it got added because it was a .networkframe 4.0 project (wrong!). I thought it was some c# support library, but it's a chromium embedded framework. I always feel like an idiot when I get things wrong, but I appreciate your time and effort. It helps me move up the curve. Again thanks!Mcgruder
H
5

I had the same issue. what worked for me is to add

    <CefSharpBuildAction>Content</CefSharpBuildAction>

to the first PropertyGroup inside the csproj of the project you are dealing with.

Hindenburg answered 2/12, 2021 at 7:15 Comment(2)
This addition made my published version of my app work, but it also increased my app size from 13.0MB to 203.0MB.Torr
The size increase is as expected as the Chromium Embedded Framework is now included with your application.Hartnett
C
3

I had the same issue even in release mode. Going through GitHub CefSharp FAQs, NOTE 2 solved my issue.

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.

Had to repair Visual Studio and all started working as before.

Catlett answered 9/3, 2018 at 17:24 Comment(1)
This page and the amount of votes are a proof that it is not so rare...Urbani
N
2

For my future me, had this same issue and every time i get this error when i start my .net core 3.1 wpf application in visual studio -> Could not load file or assembly 'CefSharp.Core.Runtime.

That cost me hours!

My Solution: Don't initialize Cef in your WinForm or WPF Window class. You need to initialize this in your startup main/app. In my example i need to add this:

public App()
{
   CefSettings _browserSettings = new CefSettings();
   ...
   Cef.Initialize(_browserSettings);
}
Nganngc answered 6/11, 2022 at 8:59 Comment(1)
If you are prepared to create a minimal example that reproduces the problem then please start a discussion so it can be determined if it's something that can be improved. github.com/cefsharp/CefSharp/discussionsHartnett
N
0

A complementary analysis to that of our colleague Tom Rutchik, I used procmon (https://learn.microsoft.com/pt-br/sysinternals/downloads/procmon) to find out which dependencies were missing, as I didn't want all my clients to install the C++ redistributable package.

enter image description here

The first one that accused was msvcp.dll... After loading CefSharp.Core.Runtime.dll the application was unable to find it in any directory. I added it to my application folder and it passed.

enter image description here

The second dll (vcruntime140.dll) crashed only after adding msvcp.dll. See that the first one has already passed successfully.

In short, I added msvcp.dll and vcruntime140.dll to my application folder and it was possible to use CefSharp without the need to install the C++ Redistributable package.

Nostril answered 4/5 at 12:52 Comment(2)
Bin deplying is officially supported by Microsoft (though they don't recommend it won't receive security updates like the installed version would). You should copy the whole VC++ Runtime, not just two files. There are some additional details in the CefSharp Wiki on where to find these files.Hartnett
There's also an example of a msbuild target that can copy the files to your bin folder at github.com/cefsharp/CefSharp/issues/3636#issuecomment-889580410 (it's for VS2019, you can easily modify it for VS2022)Hartnett

© 2022 - 2024 — McMap. All rights reserved.