{"record":{"id":"a88a9a33178495c2","repo":"cefsharp/CefSharp","slug":"registering-of-net-framework-built-in-types-is-no","errorCode":null,"errorMessage":"Registering of .Net framework built in types is not supported, create your own Object and proxy the calls if you need to access a Window/Form/Control.","messagePattern":"Registering of \\.Net framework built in types is not supported, create your own Object and proxy the calls if you need to access a Window/Form/Control\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/JavascriptObjectRepository.cs","lineNumber":242,"sourceCode":"\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\n            jsObject.PropertyInterceptor = options?.PropertyInterceptor;\n#endif\n\n            AnalyseObjectForBinding(jsObject, analyseMethods: true, analyseProperties: !isAsync, readPropertyValue: false);\n        }\n\n        /// <inheritdoc/>","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/JavascriptObjectRepository.cs#L224-L260","documentation":"Thrown by JavascriptObjectRepository.Register when the value passed in is a .NET framework built-in type. The guard rejects types where type.IsPrimitive is true or whose BaseType namespace starts with \"System.\" (e.g. System.Windows.Forms.Control, System.Windows.Window) because binding framework/CLR types directly is unsupported. The library asks you to wrap such types in your own class and proxy the calls.","triggerScenarios":"Passing a primitive (int, double, bool boxed as object), a System.* derived type, or a WinForms/WPF control (Form, Control, Window) directly to Register. Also note BaseType can be null for System.Object itself, risking a NullReferenceException instead of the documented ArgumentException.","commonSituations":"Trying to expose a Form or Window to JavaScript for convenience; registering a primitive or a BCL type like System.Collections types; binding a third-party type whose base lives in System.*.","solutions":["Create your own plain class and expose only the methods/properties you need (proxy the underlying control).","Register a small DTO/view-model wrapper instead of the framework type.","If you only need a primitive value, wrap it in a class with a property that returns the value.","Before registering, verify the type is a non-primitive user type whose base is not in the System namespace."],"exampleFix":"// before\nrepository.Register(\"form\", myWinFormsForm);\n\n// after\npublic class FormProxy\n{\n    private readonly Form _form;\n    public FormProxy(Form form) => _form = form;\n    public void Close() => _form.Close();\n    public string Title => _form.Text;\n}\nrepository.Register(\"form\", new FormProxy(myWinFormsForm));","handlingStrategy":"validation","validationCode":"static bool IsBindableType(object value)\n{\n    var t = value.GetType();\n    return !t.IsPrimitive && (t.BaseType == null || !t.BaseType.Namespace.StartsWith(\"System.\"));\n}\nif (IsBindableType(value)) repository.Register(name, value);","typeGuard":"static bool IsBindableType(object value)\n{\n    var t = value.GetType();\n    return !t.IsPrimitive && (t.BaseType == null || !t.BaseType.Namespace.StartsWith(\"System.\"));\n}","tryCatchPattern":"try { repository.Register(name, value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"built in types\"))\n{ /* wrap in a proxy class and re-register */ }","preventionTips":["Never pass Form/Control/Window or primitives directly; always wrap in your own class.","Register plain DTO/view-model types only.","Unit-test registration of each bound type."],"tags":["cefsharp","javascript-binding","type-restriction","winforms","wpf"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}