MaterialDesignInXAML/MaterialDesignInXamlToolkit · info · ArgumentNullException

textBox

Error message

textBox

What it means

RichTextBoxHintProxy is a private adapter that wires a WPF RichTextBox into MaterialDesign's SmartHint. Its constructor guards against a null RichTextBox by throwing ArgumentNullException(nameof(textBox)). Because the class is private and only ever created by HintProxyFabric.Get() (which already returns null for a null control), this guard is defensive and effectively unreachable through the public API.

Source

Thrown at src/MaterialDesignThemes.Wpf/HintProxyFabric.RichTextBox.cs:35

            var textRange = new TextRange(
                _richTextBox.Document.ContentStart,
                _richTextBox.Document.ContentEnd
            );

            return string.IsNullOrEmpty(textRange.Text) ||
                textRange.Text == Environment.NewLine;
        }

        public bool IsFocused() => _richTextBox.IsKeyboardFocused;

        public event EventHandler? ContentChanged;
        public event EventHandler? IsVisibleChanged;
        public event EventHandler? Loaded;
        public event EventHandler? FocusedChanged;

        public RichTextBoxHintProxy(RichTextBox textBox)
        {
            _richTextBox = textBox ?? throw new ArgumentNullException(nameof(textBox));
            _richTextBox.TextChanged += TextBoxTextChanged;
            _richTextBox.Loaded += TextBoxLoaded;
            _richTextBox.IsVisibleChanged += TextBoxIsVisibleChanged;
            _richTextBox.IsKeyboardFocusedChanged += TextBoxIsKeyboardFocusedChanged;
        }

        private void TextBoxIsKeyboardFocusedChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            FocusedChanged?.Invoke(sender, EventArgs.Empty);
        }

        private void TextBoxIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            IsVisibleChanged?.Invoke(sender, EventArgs.Empty);
        }

        private void TextBoxLoaded(object sender, RoutedEventArgs e)
        {

View on GitHub (pinned to 98edec3a0b)

Solutions

  1. Do not construct RichTextBoxHintProxy directly; obtain a proxy via HintProxyFabric.Get(control), which null-checks its argument.
  2. If registering a custom builder through HintProxyFabric.RegisterBuilder, return null from the build delegate when the control is null instead of constructing a proxy with a null control.
Defensive patterns

Strategy: validation

Validate before calling

// These proxies are private; prefer the public fabric entry point.
if (control is null) return null;
var proxy = HintProxyFabric.Get(control);

Prevention

When it happens

Trigger: Only reachable by instantiating RichTextBoxHintProxy through reflection, or by an internal change to HintProxyFabric that drops its null guard before casting the control to RichTextBox. Normal XAML/SmarlHint usage never calls this constructor directly.

Common situations: A developer forking the fabric or reflecting over MaterialDesign internals to add a custom hint control; never seen during ordinary control usage.

Related errors


AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13). Data as JSON: /api/errors/afa7c0ec75b81dc3. Report an issue: GitHub.