{"record":{"id":"9dcd59e0701d49b0","repo":"dotnet/wpf","slug":"sr-format-sr-invalid-iinputelement-oldcapture-gettype-9dcd59","errorCode":null,"errorMessage":"SR.Format(SR.Invalid_IInputElement, oldCapture.GetType())","messagePattern":"SR\\.Format\\(SR\\.Invalid_IInputElement, oldCapture\\.GetType\\(\\)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs","lineNumber":2087,"sourceCode":"                    }\n                    else if (o is ContentElement ce)\n                    {\n                        ce.IsEnabledChanged -= _captureIsEnabledChangedEventHandler;\n\n                        // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements.\n                        //\n                        // ce.IsVisibleChanged -= _captureIsVisibleChangedEventHandler;\n                        // ce.IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler;\n                    }\n                    else if (o is UIElement3D uie3D)\n                    {\n                        uie3D.IsEnabledChanged -= _captureIsEnabledChangedEventHandler;\n                        uie3D.IsVisibleChanged -= _captureIsVisibleChangedEventHandler;\n                        uie3D.IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler;\n                    }\n                    else\n                    {\n                        throw new InvalidOperationException(SR.Format(SR.Invalid_IInputElement, oldCapture.GetType())); \n                    }\n                }\n                if (_stylusCapture != null)\n                {\n                    o = _stylusCapture as DependencyObject;\n                    if (o is UIElement uie)\n                    {\n                        uie.IsEnabledChanged += _captureIsEnabledChangedEventHandler;\n                        uie.IsVisibleChanged += _captureIsVisibleChangedEventHandler;\n                        uie.IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler;\n                    }\n                    else if (o is ContentElement ce)\n                    {\n                        ce.IsEnabledChanged += _captureIsEnabledChangedEventHandler;\n\n                        // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements.\n                        //\n                        // ce.IsVisibleChanged += _captureIsVisibleChangedEventHandler;","sourceCodeStart":2069,"sourceCodeEnd":2105,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs#L2069-L2105","documentation":"WispLogic.ReevaluateStylusCapture (capture-release path) unsubscribes IsEnabled/IsVisible/IsHitTestVisible change handlers from the old capture element. If oldCapture is not UIElement, ContentElement, or UIElement3D, it throws InvalidOperationException naming its type, since handler wiring is only defined for those element kinds.","triggerScenarios":"Setting/changing Stylus.Capture where the previously captured object is a DependencyObject of an unsupported type; thrown synchronously when requery/capture changes (e.g. in ChangeStylusCaptureState).","commonSituations":"Custom IInputElement implementations used as capture targets; capture state corrupted by earlier invalid capture on a non-element; migrated code from mouse capture semantics.","solutions":["Always capture on UIElement/ContentElement/UIElement3D objects","Inspect Stylus.Capture(...) call sites and remove capture of custom non-element objects","If state is already corrupted, avoid capturing unsupported elements so the stale value never enters the capture path"],"exampleFix":"// before\nStylus.Capture(myCustomElement); // implements IInputElement only\n// after\nStylus.Capture(myUIElement); // UIElement-based capture target","handlingStrategy":"type-guard","validationCode":"if (oldCapture is UIElement || oldCapture is ContentElement || oldCapture is UIElement3D) { /* safe to change capture */ }","typeGuard":"bool IsSupportedCaptureElement(IInputElement e) => e is UIElement || e is ContentElement || e is UIElement3D;","tryCatchPattern":"try { Stylus.Capture(newElement); }\ncatch (InvalidOperationException ex) { Log.Warn(\"Capture state contained unsupported element\", ex); }","preventionTips":["Never capture unsupported element types — it poisons later capture changes","Validate with InputElement.IsValid before any Capture call","Audit code that mixes mouse and stylus capture"],"tags":["wpf","stylus","wisp","capture","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"}