{"record":{"id":"88fac6023a68d402","repo":"cefsharp/CefSharp","slug":"to-enable-synchronous-js-bindings-set-wcfenabled-t","errorCode":null,"errorMessage":"To enable synchronous JS bindings set WcfEnabled true in CefSharpSettings before you create your ChromiumWebBrowser instances.","messagePattern":"To enable synchronous JS bindings set WcfEnabled true in CefSharpSettings before you create your ChromiumWebBrowser instances\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/JavascriptObjectRepository.cs","lineNumber":227,"sourceCode":"            {\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.\");\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","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/JavascriptObjectRepository.cs#L209-L245","documentation":"Thrown when a .NET Framework (non-NETCOREAPP) build tries to register a SYNCHRONOUS JavaScript binding (isAsync == false) while CefSharpSettings.WcfEnabled is false AND the browser is already initialized. On the full-framework build the repo auto-sets WcfEnabled=true only if IsBrowserInitialized is false, so the guard exists because the WCF subprocess cannot be enabled after the browser has started. NETCOREAPP builds force isAsync=true and never hit this path.","triggerScenarios":"Calling IJavascriptObjectRepository.Register(...) with synchronous binding semantics on the .NET Framework build after a ChromiumWebBrowser has already been created and its underlying browser initialized, without first setting CefSharpSettings.WcfEnabled = true.","commonSituations":"App constructs the ChromiumWebBrowser early (e.g. in a Window/Form constructor or Loaded handler) and only registers bound objects later in response to a user action; migrating from a version that defaulted WcfEnabled true; or using Register instead of RegisterAsync on the framework build.","solutions":["Set CefSharpSettings.WcfEnabled = true once at startup, before any ChromiumWebBrowser instance is constructed.","Register your bound objects before the browser is initialized (move the Register call ahead of browser creation).","Switch to async bindings (RegisterAsync / IsAsync = true), which do not require WCF and are the only mode supported on .NET Core.","If you must keep sync bindings on .NET Framework, ensure no ChromiumWebBrowser is created before CefSharpSettings.WcfEnabled = true runs."],"exampleFix":"// before\nvar browser = new ChromiumWebBrowser(\"https://example.com\");\nrepository.Register(\"myObj\", new MyObj(), isAsync: false);\n\n// after\nCefSharpSettings.WcfEnabled = true; // before ANY ChromiumWebBrowser is created\nvar browser = new ChromiumWebBrowser(\"https://example.com\");\nrepository.Register(\"myObj\", new MyObj(), isAsync: false);","handlingStrategy":"validation","validationCode":"// Run once at startup, before any ChromiumWebBrowser is created:\nCefSharpSettings.WcfEnabled = true;\n// Prefer async registration on all targets:\nawait repository.RegisterAsync(...); // avoids the WCF requirement entirely","typeGuard":"if (CefSharpSettings.WcfEnabled && !isAsync) { /* sync binding is safe */ }","tryCatchPattern":null,"preventionTips":["Set CefSharpSettings.WcfEnabled at the very start of Main/Startup, before UI construction.","Prefer async bindings (RegisterAsync) which need no WCF and work on .NET Core.","Keep all Register calls ahead of ChromiumWebBrowser creation on the framework build."],"tags":["cefsharp","javascript-binding","wcf","configuration","initialization-order","net-framework"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}