{"record":{"id":"dd2ab6ddcf60aa80","repo":"cefsharp/CefSharp","slug":"object-already-bound-with-name-name","errorCode":null,"errorMessage":"Object already bound with name:{name}","messagePattern":"Object already bound with name:(.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/JavascriptObjectRepository.cs","lineNumber":235,"sourceCode":"#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.\");\n            }            \n#endif\n\n            //Validation name is unique\n            if (objects.Values.Count(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase)) > 0)\n            {\n                throw new ArgumentException(\"Object already bound with name:\" + name, name);\n            }\n\n            //Binding of System types is problematic, so we don't support it\n            var type = value.GetType();\n            if (type.IsPrimitive || type.BaseType.Namespace.StartsWith(\"System.\"))\n            {\n                throw new ArgumentException(\"Registering of .Net framework built in types is not supported, \" +\n                    \"create your own Object and proxy the calls if you need to access a Window/Form/Control.\", \"value\");\n            }\n\n            var jsObject = CreateJavascriptObject(rootObject: true);\n            jsObject.Value = value;\n            jsObject.Name = name;\n            jsObject.JavascriptName = name;\n            jsObject.IsAsync = isAsync;\n            jsObject.Binder = options?.Binder;\n            jsObject.MethodInterceptor = options?.MethodInterceptor;\n#if !NETCOREAPP","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/JavascriptObjectRepository.cs#L217-L253","documentation":"Thrown by JavascriptObjectRepository.Register when an object is already registered under the requested name. Names are compared case-insensitively (StringComparison.OrdinalIgnoreCase) across all entries in the repository, so a second Register with a colliding name is rejected. Note the ArgumentException is constructed with the bound name as the paramName argument, which surfaces in some hosts as the parameter name.","triggerScenarios":"Two calls to IJavascriptObjectRepository.Register(\"name\", obj) (or names differing only by case) targeting the same repository instance; re-registering after a hot-reload or navigation without first calling UnRegister; multiple view models binding different objects under the same logical name.","commonSituations":"Reusable control registered in more than one place; DI scope creating duplicate registrations; name typo colliding with an existing object; leftover registration from a previous page not cleaned up.","solutions":["Choose a unique name for each registered object (case-insensitive).","Call repository.UnRegister(name) before re-registering under the same name.","Guard the registration: check repository.HasBoundObject(name) (or IsBoundObjectCached) before Register.","Centralize all Register calls in one composition root to avoid duplicates across modules."],"exampleFix":"// before\nrepository.Register(\"app\", new AppVm());\nrepository.Register(\"App\", new OtherVm()); // collides (case-insensitive)\n\n// after\nif (!repository.HasBoundObject(\"app\"))\n{\n    repository.Register(\"app\", new AppVm());\n}","handlingStrategy":"validation","validationCode":"if (repository.HasBoundObject(name))\n{\n    repository.UnRegister(name); // or throw/log\n}\nrepository.Register(name, obj);","typeGuard":null,"tryCatchPattern":"try { repository.Register(name, obj); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Object already bound\"))\n{ /* log duplicate registration, use existing object */ }","preventionTips":["Centralize registration in a composition root to avoid duplicates.","Guard with HasBoundObject/IsBound before registering.","UnRegister before re-registering a name during reload."],"tags":["cefsharp","javascript-binding","duplicate-registration","naming"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}