{"record":{"id":"45101bd635fd938d","repo":"cefsharp/CefSharp","slug":"value","errorCode":null,"errorMessage":"value","messagePattern":"value","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/JavascriptObjectRepository.cs","lineNumber":210,"sourceCode":"            objects[id] = result;\n\n            return result;\n        }\n\n#if NETCOREAPP\n        public void Register(string name, object value, BindingOptions options)\n#else\n        public void Register(string name, object value, bool isAsync, BindingOptions options)\n#endif\n        {\n            if (name == null)\n            {\n                throw new ArgumentNullException(\"name\");\n            }\n\n            if (value == null)\n            {\n                throw new ArgumentNullException(\"value\");\n            }\n\n            Freeze();\n\n            //Enable WCF if not already enabled - can only be done before the browser has been initliazed\n            //if done after the subprocess won't be WCF enabled it we'll have to throw an exception\n#if NETCOREAPP\n            var isAsync = true;\n#else\n            if (!IsBrowserInitialized && !isAsync)\n            {\n                CefSharpSettings.WcfEnabled = true;\n            }\n\n            if (!CefSharpSettings.WcfEnabled && !isAsync)\n            {\n                throw new InvalidOperationException(@\"To enable synchronous JS bindings set WcfEnabled true in CefSharpSettings before you create\n                                                    your ChromiumWebBrowser instances.\");","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/JavascriptObjectRepository.cs#L192-L228","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nrepo.Register(\"myApi\", serviceInstance, new BindingOptions());\n\n// after\nif (serviceInstance == null) throw new InvalidOperationException(\"Service not resolved before binding.\");\nrepo.Register(\"myApi\", serviceInstance, new BindingOptions());","handlingStrategy":"validation","validationCode":"if (value == null)\n{\n    throw new InvalidOperationException(\"Object to bind is not resolved.\");\n}\nrepo.Register(name, value, new BindingOptions());","typeGuard":"static bool IsBindable(object value) => value != null;","tryCatchPattern":null,"preventionTips":["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."],"tags":["javascript-binding","validation","null-reference","registration","cefsharp"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}