{"record":{"id":"e3225ae79ed2de4e","repo":"dotnet/wpf","slug":"sr-format-sr-invalid-iinputelement-oldover-gettype-wisplogic","errorCode":null,"errorMessage":"SR.Format(SR.Invalid_IInputElement, oldOver.GetType())","messagePattern":"SR\\.Format\\(SR\\.Invalid_IInputElement, oldOver\\.GetType\\(\\)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs","lineNumber":2175,"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, oldOver.GetType())); \n                    }\n                }\n                if (_stylusOver != null)\n                {\n                    o = _stylusOver as DependencyObject;\n                    if (o is UIElement uie)\n                    {\n                        uie.IsEnabledChanged += _overIsEnabledChangedEventHandler;\n                        uie.IsVisibleChanged += _overIsVisibleChangedEventHandler;\n                        uie.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler;\n                    }\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;","sourceCodeStart":2157,"sourceCodeEnd":2193,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs#L2157-L2193","documentation":"WispLogic stylus-over (hover) tracking unsubscribes IsEnabled/IsVisible/IsHitTestVisible change handlers from the previous element under the stylus. If oldOver is not UIElement, ContentElement, or UIElement3D, it throws InvalidOperationException naming its type, because over-tracking handler management only supports those element kinds.","triggerScenarios":"The element previously tracked as StylusDirectlyOver was not a supported input element type — typically after hover state was seeded with a non-element DependencyObject; thrown when stylus-over state changes (PROMOTE/mouse-promotion or actual pen movement).","commonSituations":"Custom IInputElement hit-test results fed into stylus-over tracking; hover over DrawingVisual-hosted content without a wrapping element; mixed mouse-promotion code paths using non-element visuals.","solutions":["Ensure hit-test/over targets resolve to UIElement/ContentElement/UIElement3D (wrap DrawingVisuals in a UIElement host)","Verify InputElement.IsValid on elements entering stylus-over tracking","Audit custom hit-test overrides that return non-element visuals directly"],"exampleFix":"// before\nSetStylusOver(drawingVisual, ...); // unsupported over target\n// after\nSetStylusOver(FindAncestor<UIElement>(drawingVisual), ...);","handlingStrategy":"type-guard","validationCode":"if (element is UIElement || element is ContentElement || element is UIElement3D) { /* safe for stylus-over tracking */ }","typeGuard":"bool IsSupportedOverElement(IInputElement e) => e is UIElement || e is ContentElement || e is UIElement3D;","tryCatchPattern":"try { UpdateStylusOver(newElement); }\ncatch (InvalidOperationException ex) { Log.Warn(\"Stylus-over target unsupported\", ex); }","preventionTips":["Ensure hit-test results resolve to supported input elements","Host raw visuals in UIElement wrappers","Avoid custom hit-test overrides that return non-element visuals"],"tags":["wpf","stylus","wisp","hover","invalid-operation"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}