{"record":{"id":"bc857bc65e5553b1","repo":"dotnet/wpf","slug":"sr-format-sr-invalid-iinputelement-stylusover-gettype-bc857b","errorCode":null,"errorMessage":"SR.Format(SR.Invalid_IInputElement, _stylusOver.GetType())","messagePattern":"SR\\.Format\\(SR\\.Invalid_IInputElement, _stylusOver\\.GetType\\(\\)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs","lineNumber":2204,"sourceCode":"                    }\n                    else if (o is ContentElement ce)\n                    {\n                        ce.IsEnabledChanged += _overIsEnabledChangedEventHandler;\n\n                        // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements.\n                        //\n                        // ce.IsVisibleChanged += _overIsVisibleChangedEventHandler;\n                        // ce.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler;\n                    }\n                    else if (o is UIElement3D uie3D)\n                    {\n                        uie3D.IsEnabledChanged += _overIsEnabledChangedEventHandler;\n                        uie3D.IsVisibleChanged += _overIsVisibleChangedEventHandler;\n                        uie3D.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler;\n                    }\n                    else\n                    {\n                        throw new InvalidOperationException(SR.Format(SR.Invalid_IInputElement, _stylusOver.GetType())); \n                    }\n                }\n\n                // Oddly enough, update the IsStylusOver property first.  This is\n                // so any callbacks will see the more-common IsStylusOver property\n                // set correctly.\n                UIElement.StylusOverProperty.OnOriginValueChanged(oldOver as DependencyObject, _stylusOver as DependencyObject, ref _stylusOverTreeState);\n\n                // Invalidate the IsStylusDirectlyOver property.\n                if (oldOver != null)\n                {\n                    o = oldOver as DependencyObject;\n                    o.SetValue(UIElement.IsStylusDirectlyOverPropertyKey, false); // Same property for ContentElements\n                }\n                if (_stylusOver != null)\n                {\n                    o = _stylusOver as DependencyObject;\n                    o.SetValue(UIElement.IsStylusDirectlyOverPropertyKey, true); // Same property for ContentElements","sourceCodeStart":2186,"sourceCodeEnd":2222,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs#L2186-L2222","documentation":"WispLogic.ChangeStylusOver (WispLogic.cs:2204) throws InvalidOperationException(SR.Invalid_IInputElement) when the element currently under the stylus (_stylusOver) is neither a UIElement, ContentElement, nor UIElement3D. The WPF stylus input system only tracks those three input element types, so it fails fast instead of silently skipping hit-testable-event bookkeeping. It indicates an IInputElement reached internal stylus state that the stylus stack cannot handle.","triggerScenarios":"ChangeStylusOver is called (e.g. from stylus move/enter processing) with _stylusOver set to an object that passed IInputElement hit testing but fails the is-UIElement/is-ContentElement/is-UIElement3D pattern match — i.e. a custom IInputElement implementation feeding the stylus over-state.","commonSituations":"Custom control frameworks implementing IInputElement directly instead of deriving from UIElement/ContentElement; third-party presentation surfaces injecting foreign elements into the input tree; internal state corruption after re-templating or visual-tree mutations during stylus input.","solutions":["Ensure the element under the stylus derives from UIElement, ContentElement, or UIElement3D rather than implementing IInputElement directly.","Audit custom hit-test / input code that may assign a non-standard IInputElement to the stylus over-path.","Reproduce under debugger and inspect _stylusOver.GetType() to identify the foreign element type and its creator."],"exampleFix":"// before\nclass MyElement : FrameworkContentElement, IInputElement { } // ok, but a raw IInputElement is not\n// after\nclass MyElement : UIElement { } // derive from a supported input element base","handlingStrategy":"type-guard","validationCode":"static bool CanBeStylusOver(object e) => e is UIElement || e is ContentElement || e is UIElement3D;","typeGuard":"static bool IsValidInputElement(IInputElement e) => e is UIElement || e is ContentElement || e is UIElement3D;","tryCatchPattern":"try { /* stylus over handling */ } catch (InvalidOperationException ex) when (ex.Message.Contains(\"IInputElement\")) { /* log and fall back to mouse handling */ }","preventionTips":["Derive custom controls from UIElement/ContentElement/UIElement3D, never implement IInputElement directly","Keep hit-test results within supported element types","Test custom controls with a stylus/touch device"],"tags":["wpf","stylus","invalidoperation","input"],"backgroundTag":"incompatible-source-type","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}