{"record":{"id":"b63eec161ea49ca5","repo":"dotnet/wpf","slug":"sr-format-sr-invalid-iinputelement-oldover-gettype-b63eec","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/WispStylusDevice.cs","lineNumber":407,"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":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs#L389-L425","documentation":"WispStylusDevice.UpdateOverProperty (WispStylusDevice.cs:407) throws InvalidOperationException(SR.Invalid_IInputElement) when detaching event handlers (IsEnabledChanged, IsVisibleChanged, IsHitTestVisibleChanged) from oldOver — the previous stylus-over element — and oldOver is not UIElement, ContentElement, or UIElement3D. The over-state bookkeeping expects only those element kinds, so a foreign element in _stylusOver state fails fast.","triggerScenarios":"ChangeStylusOver transitions the stylus-over element while the stored previous element is a non-standard IInputElement, usually because it was accepted earlier without validation.","commonSituations":"Custom IInputElement implementations in the hit-test path; state corruption after visual-tree surgery during stylus moves; third-party input frameworks injecting elements.","solutions":["Ensure all elements that can be under the stylus derive from UIElement, ContentElement, or UIElement3D.","Inspect oldOver.GetType() in a debugger to find the source of the foreign element.","Remove custom hit-test code that returns raw IInputElement implementations."],"exampleFix":"// before\nclass Tile : DependencyObject, IInputElement { }\n// after\nclass Tile : UIElement { }","handlingStrategy":"type-guard","validationCode":"static bool TracksStylusOver(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 transition */ } catch (InvalidOperationException ex) when (ex.Message.Contains(\"IInputElement\")) { /* clear stylus state and fall back to mouse input */ }","preventionTips":["Keep all hit-testable elements within UIElement/ContentElement/UIElement3D hierarchy","Avoid third-party IInputElement implementations in the visual tree","Debug oldOver.GetType() early when integrating custom input frameworks"],"tags":["wpf","stylus","invalidoperation","hit-testing"],"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"}