cefsharp/CefSharp · critical · FileNotFoundException
NotFound
Error message
NotFound
What it means
CefLibraryHandle is a SafeHandle that loads libcef.dll via LoadLibraryEx during construction. If the DLL file does not exist at the given path, FileNotFoundException is thrown with 'NotFound' as the message and the path as the fileName. This is the earliest failure point for native CEF loading.
Source
Thrown at CefSharp/CefLibraryHandle.cs:43
private enum LoadLibraryFlags : uint
{
DONT_RESOLVE_DLL_REFERENCES = 0x00000001,
LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010,
LOAD_LIBRARY_AS_DATAFILE = 0x00000002,
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040,
LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020,
LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008
}
/// <summary>
/// Initializes a new instance of the CefLibraryHandle class.
/// </summary>
/// <param name="path">libcef.dll full path.</param>
public CefLibraryHandle(string path) : base(IntPtr.Zero, true)
{
if (!File.Exists(path))
{
throw new FileNotFoundException("NotFound", path);
}
var handle = LoadLibraryEx(path, IntPtr.Zero, LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH);
base.SetHandle(handle);
}
/// <summary>
/// When overridden in a derived class, gets a value indicating whether the handle value is invalid.
/// </summary>
/// <value>
/// true if the handle value is invalid; otherwise, false.
/// </value>
public override bool IsInvalid
{
get { return handle == IntPtr.Zero; }
}
/// <summary>View on GitHub (pinned to 16bc6e0711)
Solutions
- Verify libcef.dll exists in the same directory as the executing assembly (or in the path you configured).
- Clean-rebuild the project to let CefSharp.AfterBuild.targets copy all native files.
- If using AnyCPU, ensure the x86/x64 subfolders each contain libcef.dll.
- Check that the working directory at runtime matches where the binaries are deployed.
Example fix
// before — app runs from a different directory, libcef.dll not found
var settings = new CefSettings { BrowserSubprocessPath = "CefSharp.BrowserSubProcess.exe" };
Cef.Initialize(settings);
// after — use absolute paths
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
var settings = new CefSettings
{
BrowserSubprocessPath = Path.Combine(baseDir, "CefSharp.BrowserSubProcess.exe")
};
Cef.Initialize(settings, performDependencyCheck: true); Defensive patterns
Strategy: validation
Validate before calling
var libcefPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "libcef.dll");
if (!File.Exists(libcefPath))
{
throw new FileNotFoundException(
$"libcef.dll not found at {libcefPath}. " +
"Ensure CEF NuGet packages are restored and AfterBuild targets ran.");
}
// safe to initialize CEF now Try / catch
try
{
Cef.Initialize(settings);
}
catch (FileNotFoundException ex) when (ex.Message == "NotFound")
{
Console.Error.WriteLine($"libcef.dll missing at: {ex.FileName}");
throw;
} Prevention
- Always verify libcef.dll exists in the output directory before running.
- Clean-rebuild to ensure CefSharp.AfterBuild.targets copies all native files.
- Use absolute paths for BrowserSubprocessPath and resource directories.
When it happens
Trigger: Cef.Initialize internally creates a CefLibraryHandle with the resolved libcef.dll path. If the file is absent — wrong working directory, incomplete deployment, or a misconfigured BrowserSubProcessPath — File.Exists returns false and the exception fires.
Common situations: Running the app from a directory that does not contain libcef.dll. Build output missing native files due to a broken AfterBuild target or failed NuGet restore. Publishing/deploying without the CEF redist files. 32-bit process looking in the wrong folder.
Related errors
- Unable to load for arch {env}
- Cef.Initialize() failed.Check the log file see https://githu
- Unable to locate required Cef/CefSharp dependencies:
- Unable to Initialize Cef
- Cef.IsInitialized was false!.Check the log file for errors!.
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/fc67fdfb84f6d727.
Report an issue: GitHub.