cefsharp/CefSharp · error · Exception
UseAnyCpuAssemblyResolver has already been called, call
Error message
UseAnyCpuAssemblyResolver has already been called, call
What it means
SubscribeAnyCpuAssemblyResolver hooks an AppDomain.AssemblyResolve handler to load the architecture-specific CefSharp.Core.Runtime.dll at runtime. It tracks whether it has already been called via a static field; calling it a second time throws because double-subscribing would create duplicate resolve handlers and unpredictable assembly loading.
Source
Thrown at CefSharp/CefRuntime.cs:37
/// <summary>
/// When using AnyCPU the architecture specific version of CefSharp.Core.Runtime.dll
/// needs to be loaded (x64/x86).
/// This method subscribes to the <see cref="AppDomain.AssemblyResolve"/> event
/// for <see cref="AppDomain.CurrentDomain"/> and loads the CefSharp.Core.Runtime.dll
/// based on <see cref="Environment.Is64BitProcess"/>.
/// This method MUST be called before you call Cef.Initialize, create your first ChromiumWebBrowser instance, basically
/// before anything CefSharp related happens. This method is part of CefSharp.dll which is an AnyCPU library and
/// doesn't have any references to the CefSharp.Core.Runtime.dll so it's safe to use.
/// </summary>
/// <param name="basePath">
/// The path containing the x64/x86 folders which contain the CefSharp/CEF resources.
/// If null then AppDomain.CurrentDomain.SetupInformation.ApplicationBase will be used as the path.
/// (</param>
public static void SubscribeAnyCpuAssemblyResolver(string basePath = null)
{
if(currentDomainAssemblyResolveHandler != null)
{
throw new Exception("UseAnyCpuAssemblyResolver has already been called, call ");
}
if(basePath == null)
{
basePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
}
currentDomainAssemblyResolveHandler = (sender, args) =>
{
if (args.Name.StartsWith("CefSharp.Core.Runtime"))
{
string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
string archSpecificPath = Path.Combine(basePath,
Environment.Is64BitProcess ? "x64" : "x86",
assemblyName);
return File.Exists(archSpecificPath)
? System.Reflection.Assembly.LoadFile(archSpecificPath)View on GitHub (pinned to 16bc6e0711)
Solutions
- Call SubscribeAnyCpuAssemblyResolver exactly once at application entry point.
- If re-subscription is legitimately needed, call UnsubscribeAnyCpuAssemblyResolver first.
- Guard the call with a check of whether CEF is already initialized or the resolver is already active.
Example fix
// before — called in two places CefRuntime.SubscribeAnyCpuAssemblyResolver(); // ... later, in another module ... CefRuntime.SubscribeAnyCpuAssemblyResolver(); // throws // after — call once, or unsubscribe first CefRuntime.UnsubscribeAnyCpuAssemblyResolver(); CefRuntime.SubscribeAnyCpuAssemblyResolver(newBasePath);
Defensive patterns
Strategy: validation
Validate before calling
// CefRuntime does not expose the internal flag publicly.
// Track it yourself:
private static int resolverSubscribed = 0;
if (Interlocked.CompareExchange(ref resolverSubscribed, 1, 0) == 1)
{
// already subscribed, skip or unsubscribe first
return;
}
CefRuntime.SubscribeAnyCpuAssemblyResolver(basePath); Try / catch
try
{
CefRuntime.SubscribeAnyCpuAssemblyResolver(basePath);
}
catch (Exception ex) when (ex.Message.Contains("already been called"))
{
Log.Info("AnyCPU resolver already subscribed — skipping");
} Prevention
- Call SubscribeAnyCpuAssemblyResolver exactly once in Program.Main or the app entry point.
- If re-subscription is needed, call UnsubscribeAnyCpuAssemblyResolver first.
- Avoid calling it from library initializers that may run multiple times.
When it happens
Trigger: Calling CefRuntime.SubscribeAnyCpuAssemblyResolver() more than once in the same AppDomain without calling UnsubscribeAnyCpuAssemblyResolver in between.
Common situations: Application startup code and a DI container initializer both calling it. Test fixtures that re-run startup logic without cleanup. A library that calls it internally while the host app also calls it.
Related errors
- Unable to load for arch {env}
- Cef.Initialize() failed.Check the log file see https://githu
- Unable to Initialize Cef
- Cef.Initialize() failed.Check the log file see https://githu
- 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/4742e2f408bfe9bd.
Report an issue: GitHub.