{"record":{"id":"a50b84a7e75f971c","repo":"dotnet/wpf","slug":"sr-format-sr-invalid-iinputelement-styluscapture-gettype-a50b84","errorCode":null,"errorMessage":"SR.Format(SR.Invalid_IInputElement, _stylusCapture.GetType())","messagePattern":"SR\\.Format\\(SR\\.Invalid_IInputElement, _stylusCapture\\.GetType\\(\\)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs","lineNumber":2116,"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, _stylusCapture.GetType())); \n                    }\n                }\n\n                // Oddly enough, update the IsStylusCaptureWithin property first.  This is\n                // so any callbacks will see the more-common IsStylusCaptureWithin property\n                // set correctly.\n                UIElement.StylusCaptureWithinProperty.OnOriginValueChanged(oldCapture as DependencyObject, _stylusCapture as DependencyObject, ref _stylusCaptureWithinTreeState);\n\n                // Invalidate the IsStylusCaptured properties.\n                if (oldCapture != null)\n                {\n                    o = oldCapture as DependencyObject;\n                    o.SetValue(UIElement.IsStylusCapturedPropertyKey, false); // Same property for ContentElements\n                }\n                if (_stylusCapture != null)\n                {\n                    o = _stylusCapture as DependencyObject;\n                    o.SetValue(UIElement.IsStylusCapturedPropertyKey, true); // Same property for ContentElements","sourceCodeStart":2098,"sourceCodeEnd":2134,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs#L2098-L2134","documentation":"WispLogic capture-apply path subscribes IsEnabled/IsVisible/IsHitTestVisible change handlers to the new _stylusCapture. When the capture target is neither UIElement, ContentElement, nor UIElement3D, no handler wiring is possible, so it throws InvalidOperationException naming the type. This mirrors error 697 but fires when establishing capture rather than releasing it.","triggerScenarios":"Calling Stylus.Capture(element, ...) or StylusDevice.Capture with an element that is a DependencyObject but not one of the three supported input element types; the throw happens while wiring change notifications in WispLogic.","commonSituations":"Capturing a DrawingVisual or custom IInputElement; interop code capturing on non-element visuals; unit-test fakes passed to Stylus.Capture.","solutions":["Derive the capture target from UIElement (or ContentElement/UIElement3D)","Capture the nearest supported ancestor instead of the visual itself","Add a guard with InputElement.IsValid(element) before calling Capture"],"exampleFix":"// before\nStylus.Capture(drawingVisual, CaptureMode.Element);\n// after\nif (InputElement.IsValid(drawingVisual))\n    Stylus.Capture(drawingVisual, CaptureMode.Element);\nelse\n    Stylus.Capture(FindAncestor<UIElement>(drawingVisual), CaptureMode.Element);","handlingStrategy":"type-guard","validationCode":"if (InputElement.IsValid(element))\n    Stylus.Capture(element, CaptureMode.Element);","typeGuard":"bool CanCapture(IInputElement e) => e is UIElement || e is ContentElement || e is UIElement3D;","tryCatchPattern":"try { Stylus.Capture(element, CaptureMode.Element); }\ncatch (InvalidOperationException ex) { Log.Warn(\"Invalid stylus capture element\", ex); }","preventionTips":["Always derive capture targets from UIElement","Wrap DrawingVisual content in a UIElement host before capture","Use InputElement.IsValid as a pre-capture gate"],"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-21T21:30:21.729Z"}