{"record":{"id":"169fcb072e4c452a","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"canbuild","errorCode":null,"errorMessage":"canBuild","messagePattern":"canBuild","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignThemes.Wpf/HintProxyFabric.cs","lineNumber":12,"sourceCode":"﻿namespace MaterialDesignThemes.Wpf;\n\npublic static partial class HintProxyFabric\n{\n    private sealed class HintProxyBuilder\n    {\n        private readonly Func<Control?, bool> _canBuild;\n        private readonly Func<Control, IHintProxy> _build;\n\n        public HintProxyBuilder(Func<Control?, bool> canBuild, Func<Control, IHintProxy> build)\n        {\n            _canBuild = canBuild ?? throw new ArgumentNullException(nameof(canBuild));\n            _build = build ?? throw new ArgumentNullException(nameof(build));\n        }\n\n        public bool CanBuild(Control? control) => _canBuild(control);\n        public IHintProxy? Build(Control control) => _build(control);\n    }\n\n    private static readonly List<HintProxyBuilder> Builders = new();\n\n    static HintProxyFabric()\n    {\n        Builders.Add(new HintProxyBuilder(c => c is ComboBox, c => new ComboBoxHintProxy((ComboBox)c)));\n        Builders.Add(new HintProxyBuilder(c => c is TextBox, c => new TextBoxHintProxy((TextBox)c)));\n        Builders.Add(new HintProxyBuilder(c => c is RichTextBox, c => new RichTextBoxHintProxy((RichTextBox)c)));\n        Builders.Add(new HintProxyBuilder(c => c is PasswordBox, c => new PasswordBoxHintProxy((PasswordBox)c)));\n    }\n\n    public static void RegisterBuilder(Func<Control?, bool> canBuild, Func<Control, IHintProxy> build)","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignThemes.Wpf/HintProxyFabric.cs#L1-L30","documentation":"HintProxyBuilder is the internal registration record behind HintProxyFabric.RegisterBuilder. Its constructor rejects a null canBuild predicate (and separately a null build delegate) so that Get() can never dereference a null Func when walking the builder list. The exception surfaces at registration time, not later when a SmartHint tries to resolve a control.","triggerScenarios":"Calling HintProxyFabric.RegisterBuilder(null, build) or RegisterBuilder(canBuild, null), i.e. passing a null Func for either the matcher or the builder.","commonSituations":"Registering a custom hint control (e.g. a third-party text box) into SmartHint and accidentally passing a null lambda, often after a refactor that removed the predicate.","solutions":["Pass a non-null Func<Control?, bool> for canBuild and a non-null Func<Control, IHintProxy> for build.","If you have no filtering predicate, supply c => c is YourControl (or _ => true) for canBuild.","Register the builder once at application startup, after the control type is known."],"exampleFix":"// before\nHintProxyFabric.RegisterBuilder(null, c => new MyHintProxy(c));\n// after\nHintProxyFabric.RegisterBuilder(c => c is MyControl, c => new MyHintProxy((MyControl)c));","handlingStrategy":"validation","validationCode":"if (canBuild is null) throw new ArgumentNullException(nameof(canBuild));\nif (build is null) throw new ArgumentNullException(nameof(build));\nHintProxyFabric.RegisterBuilder(canBuild, build);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provide a concrete matcher (c => c is YourControl) when registering builders.","Register custom builders once at startup and unit-test them in isolation."],"tags":["wpf","smarthint","argument-null","registration"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}