{"record":{"id":"73c523ce65e45501","repo":"dotnet/wpf","slug":"sr-format-sr-invalid-iinputelement-oldover-gettype","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/Pointer/PointerLogic.cs","lineNumber":626,"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 element3D)\n                    {\n                        element3D.IsEnabledChanged -= _overIsEnabledChangedEventHandler;\n                        element3D.IsVisibleChanged -= _overIsVisibleChangedEventHandler;\n                        element3D.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 element)\n                    {\n                        element.IsEnabledChanged += _overIsEnabledChangedEventHandler;\n                        element.IsVisibleChanged += _overIsVisibleChangedEventHandler;\n                        element.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":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerLogic.cs#L608-L644","documentation":"PointerLogic.UpdateOverProperty unsubscribes stylus-over event handlers from the previous 'over' element. If oldOver is a DependencyObject but not UIElement, ContentElement, or UIElement3D, InvalidOperationException (SR.Invalid_IInputElement with oldOver.GetType()) is thrown.","triggerScenarios":"The stylus-over (hover) element becoming an unsupported IInputElement type during over-property update, e.g. hover moving onto a foreign element after a previous supported element, or an unsupported element previously registered as over.","commonSituations":"Custom hit-test results producing non-standard elements tracked as stylus-over; mixing third-party visual frameworks with WPF stylus input.","solutions":["Ensure elements participating in stylus over-tracking are one of the three supported types","Filter hit-test results to supported element types before feeding input logic","Subclass UIElement/ContentElement/UIElement3D for custom visuals that need stylus hover"],"exampleFix":"// before\nhitTestResults.ForEach(r => TrackStylusOver(r.Visual)); // may include custom elements\n// after\nvar supported = hitTestResults.Where(r => r.Visual is UIElement || r.Visual is ContentElement || r.Visual is UIElement3D);\nforeach (var r in supported) TrackStylusOver(r.Visual);","handlingStrategy":"type-guard","validationCode":"if (!(target is UIElement || target is ContentElement || target is UIElement3D)) return; // skip unsupported over targets","typeGuard":"static bool IsSupportedInputElement(IInputElement e) => e is UIElement || e is ContentElement || e is UIElement3D;","tryCatchPattern":"try { TrackStylusOver(element); }\ncatch (InvalidOperationException) { /* untrack the element and continue */ }","preventionTips":["Filter hit-test results to supported element types","Use UIElement-derived classes for visuals involved in stylus hover"],"tags":["wpf","stylus","pointer","invalid-operation"],"backgroundTag":"invalid-state-transition","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"}