stride3d/stride · error · InvalidOperationException

Unable to reach the NotifyListItemClicked internal method…

Error message

Unable to reach the NotifyListItemClicked internal method from ListBox class.

What it means

EditableContentListBoxItem's static constructor reflects ListBox.NotifyListItemClicked (private instance method) once per type load. If the method cannot be found — different .NET/WPF runtime version where the internal was renamed or removed — it throws InvalidOperationException, since item click editing would silently break.

Solutions

  1. Update the reflection lookup to the method name/signature present in the target runtime, or wrap in a cross-version resolver trying several names
  2. Replace the internal-method invocation with public API: handle clicks via ListBoxItem.Selected / PreviewMouseLeftButtonDown yourself
  3. Catch TypeInitializationException at startup and log typeof(ListBox) runtime version to diagnose

Example fix

// before
NotifyListItemClickedMethod = typeof(ListBox).GetMethod("NotifyListItemClicked", BindingFlags.Instance | BindingFlags.NonPublic);
if (NotifyListItemClickedMethod == null)
    throw new InvalidOperationException("Unable to reach ...");
// after
NotifyListItemClickedMethod = typeof(ListBox).GetMethod("NotifyListItemClicked", BindingFlags.Instance | BindingFlags.NonPublic)
    ?? typeof(ListBox).GetMethod("NotifyListItemClicked", BindingFlags.Instance | BindingFlags.Public);
if (NotifyListItemClickedMethod == null)
    NotifyListItemClickedMethod = null; // fall back to public click handling
Defensive patterns

Strategy: try-catch

Validate before calling

var m = typeof(ListBox).GetMethod("NotifyListItemClicked", BindingFlags.Instance | BindingFlags.NonPublic);
if (m == null) log.Warn("ListBox.NotifyListItemClicked unavailable on this runtime; using fallback click handling");

Type guard

static bool SupportsNotifyListItemClicked() => typeof(ListBox).GetMethod("NotifyListItemClicked", BindingFlags.Instance | BindingFlags.NonPublic) != null;

Try / catch

try { InitializeListBoxInternals(); }
catch (TypeInitializationException ex) { log.Error("EditableContentListBoxItem static init failed", ex); UsePublicClickHandling = true; }

Prevention

When it happens

Trigger: First use of EditableContentListBoxItem (type initializer) on a runtime (e.g. .NET Core 3.x/5+ vs .NET Framework) where ListBox.NotifyListItemClicked does not exist or its signature changed.

Common situations: Migrating the editor from .NET Framework to .NET Core where WPF internals changed; running on a patched runtime with internal API differences; trimming/AOT stripping internals.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/88107cfd209a1229. Report an issue: GitHub.

Appendix: source

Thrown at sources/editor/Stride.Core.Assets.Editor/View/Controls/EditableContentListBox.cs:134

        private static readonly MethodInfo NotifyListItemClickedMethod;

        private readonly DataTemplate regularContentTemplate;
        private readonly DataTemplateSelector regularContentTemplateSelector;

        private readonly DataTemplate editContentTemplate;
        private readonly DataTemplateSelector editContentTemplateSelector;

        private bool mouseDown;

        public static readonly DependencyProperty CanEditProperty = DependencyProperty.Register("CanEdit", typeof(bool), typeof(EditableContentListBoxItem), new PropertyMetadata(true));

        public static readonly DependencyProperty IsEditingProperty = DependencyProperty.Register("IsEditing", typeof(bool), typeof(EditableContentListBoxItem), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsEditingPropertyChanged));

        static EditableContentListBoxItem()
        {
            NotifyListItemClickedMethod = typeof(ListBox).GetMethod("NotifyListItemClicked", BindingFlags.Instance | BindingFlags.NonPublic);
            if (NotifyListItemClickedMethod == null)
                throw new InvalidOperationException("Unable to reach the NotifyListItemClicked internal method from ListBox class.");
        }

        internal EditableContentListBoxItem(
            DataTemplate regularContentTemplate,
            DataTemplateSelector regularContentTemplateSelector,
            DataTemplate editContentTemplate,
            DataTemplateSelector editContentTemplateSelector)
        {
            this.regularContentTemplate = regularContentTemplate;
            this.regularContentTemplateSelector = regularContentTemplateSelector;
            this.editContentTemplate = editContentTemplate;
            this.editContentTemplateSelector = editContentTemplateSelector;
        }

        public bool IsEditing { get { return (bool)GetValue(IsEditingProperty); } set { SetValue(IsEditingProperty, value); } }

        public bool CanEdit { get { return (bool)GetValue(CanEditProperty); } set { SetValue(CanEditProperty, value); } }

View on GitHub (pinned to 96fad776d2)