MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · ArgumentNullException
canBuild
Error message
canBuild
What it means
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.
Source
Thrown at src/MaterialDesignThemes.Wpf/HintProxyFabric.cs:12
namespace MaterialDesignThemes.Wpf;
public static partial class HintProxyFabric
{
private sealed class HintProxyBuilder
{
private readonly Func<Control?, bool> _canBuild;
private readonly Func<Control, IHintProxy> _build;
public HintProxyBuilder(Func<Control?, bool> canBuild, Func<Control, IHintProxy> build)
{
_canBuild = canBuild ?? throw new ArgumentNullException(nameof(canBuild));
_build = build ?? throw new ArgumentNullException(nameof(build));
}
public bool CanBuild(Control? control) => _canBuild(control);
public IHintProxy? Build(Control control) => _build(control);
}
private static readonly List<HintProxyBuilder> Builders = new();
static HintProxyFabric()
{
Builders.Add(new HintProxyBuilder(c => c is ComboBox, c => new ComboBoxHintProxy((ComboBox)c)));
Builders.Add(new HintProxyBuilder(c => c is TextBox, c => new TextBoxHintProxy((TextBox)c)));
Builders.Add(new HintProxyBuilder(c => c is RichTextBox, c => new RichTextBoxHintProxy((RichTextBox)c)));
Builders.Add(new HintProxyBuilder(c => c is PasswordBox, c => new PasswordBoxHintProxy((PasswordBox)c)));
}
public static void RegisterBuilder(Func<Control?, bool> canBuild, Func<Control, IHintProxy> build)View on GitHub (pinned to 98edec3a0b)
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.
Example fix
// before HintProxyFabric.RegisterBuilder(null, c => new MyHintProxy(c)); // after HintProxyFabric.RegisterBuilder(c => c is MyControl, c => new MyHintProxy((MyControl)c));
Defensive patterns
Strategy: validation
Validate before calling
if (canBuild is null) throw new ArgumentNullException(nameof(canBuild)); if (build is null) throw new ArgumentNullException(nameof(build)); HintProxyFabric.RegisterBuilder(canBuild, build);
Prevention
- Provide a concrete matcher (c => c is YourControl) when registering builders.
- Register custom builders once at startup and unit-test them in isolation.
When it happens
Trigger: Calling HintProxyFabric.RegisterBuilder(null, build) or RegisterBuilder(canBuild, null), i.e. passing a null Func for either the matcher or the builder.
Common situations: 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.
Related errors
AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13).
Data as JSON: /api/errors/169fcb072e4c452a.
Report an issue: GitHub.