cefsharp/CefSharp · error · ArgumentNullException
value
Error message
value
What it means
Thrown by JavascriptObjectRepository.Register when the value (the .NET object to bind) is null. CefSharp reflects over the object to generate JavaScript-callable proxies; a null target has no methods/properties to bind, so Register rejects it with ArgumentNullException. This check runs before Freeze() and before the system-type validation.
Source
Thrown at CefSharp/Internals/JavascriptObjectRepository.cs:210
objects[id] = result;
return result;
}
#if NETCOREAPP
public void Register(string name, object value, BindingOptions options)
#else
public void Register(string name, object value, bool isAsync, BindingOptions options)
#endif
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (value == null)
{
throw new ArgumentNullException("value");
}
Freeze();
//Enable WCF if not already enabled - can only be done before the browser has been initliazed
//if done after the subprocess won't be WCF enabled it we'll have to throw an exception
#if NETCOREAPP
var isAsync = true;
#else
if (!IsBrowserInitialized && !isAsync)
{
CefSharpSettings.WcfEnabled = true;
}
if (!CefSharpSettings.WcfEnabled && !isAsync)
{
throw new InvalidOperationException(@"To enable synchronous JS bindings set WcfEnabled true in CefSharpSettings before you create
your ChromiumWebBrowser instances.");View on GitHub (pinned to 16bc6e0711)
Solutions
- Ensure the object instance is constructed and non-null before calling Register.
- Validate the value from DI/factory sources and fail loudly or skip if null.
- Avoid registering types whose base namespace is System.* (a later check rejects built-in types) — wrap them in your own class.
Example fix
// before
repo.Register("myApi", serviceInstance, new BindingOptions());
// after
if (serviceInstance == null) throw new InvalidOperationException("Service not resolved before binding.");
repo.Register("myApi", serviceInstance, new BindingOptions()); Defensive patterns
Strategy: validation
Validate before calling
if (value == null)
{
throw new InvalidOperationException("Object to bind is not resolved.");
}
repo.Register(name, value, new BindingOptions()); Type guard
static bool IsBindable(object value) => value != null;
Prevention
- Resolve and verify the object instance from DI/factory before binding.
- Skip or log null entries in dynamic binding loops.
- Wrap System.* types in your own class since built-in types are rejected later.
When it happens
Trigger: Calling Register(name, null, ...) where the object to expose was never instantiated, came from a DI/factory that returned null, or was conditionally created and the condition was false.
Common situations: DI container failing to resolve the bound service; a factory method returning null on misconfiguration; binding in a loop where some entries have no instance yet; lazy initialization that has not run before Register.
Related errors
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/45101bd635fd938d.
Report an issue: GitHub.