dotnet/wpf · error · InvalidOperationException
SR.Format(SR.Invalid_IInputElement, oldOver.GetType())
Error message
SR.Format(SR.Invalid_IInputElement, oldOver.GetType())
What it means
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.
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
Example fix
// before hitTestResults.ForEach(r => TrackStylusOver(r.Visual)); // may include custom elements // after var supported = hitTestResults.Where(r => r.Visual is UIElement || r.Visual is ContentElement || r.Visual is UIElement3D); foreach (var r in supported) TrackStylusOver(r.Visual);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(target is UIElement || target is ContentElement || target is UIElement3D)) return; // skip unsupported over targets
Type guard
static bool IsSupportedInputElement(IInputElement e) => e is UIElement || e is ContentElement || e is UIElement3D;
Try / catch
try { TrackStylusOver(element); }
catch (InvalidOperationException) { /* untrack the element and continue */ } Prevention
- Filter hit-test results to supported element types
- Use UIElement-derived classes for visuals involved in stylus hover
When it happens
Trigger: 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.
Common situations: Custom hit-test results producing non-standard elements tracked as stylus-over; mixing third-party visual frameworks with WPF stylus input.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- SR.Format(SR.Invalid_IInputElement, oldCapture.GetType())
- SR.Format(SR.Invalid_IInputElement…
- SR.Format(SR.Invalid_IInputElement, _stylusOver.GetType())
- SR.Format(SR.Invalid_IInputElement…
- SR.Format(SR.Invalid_IInputElement, oldCapture.GetType())
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/73c523ce65e45501.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerLogic.cs:626
}
else if (o is ContentElement ce)
{
ce.IsEnabledChanged -= _overIsEnabledChangedEventHandler;
// NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements.
//
// ce.IsVisibleChanged -= _overIsVisibleChangedEventHandler;
// ce.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler;
}
else if (o is UIElement3D element3D)
{
element3D.IsEnabledChanged -= _overIsEnabledChangedEventHandler;
element3D.IsVisibleChanged -= _overIsVisibleChangedEventHandler;
element3D.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler;
}
else
{
throw new InvalidOperationException(SR.Format(SR.Invalid_IInputElement, oldOver.GetType()));
}
}
if (_stylusOver != null)
{
o = _stylusOver as DependencyObject;
if (o is UIElement element)
{
element.IsEnabledChanged += _overIsEnabledChangedEventHandler;
element.IsVisibleChanged += _overIsVisibleChangedEventHandler;
element.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler;
}
else if (o is ContentElement ce)
{
ce.IsEnabledChanged += _overIsEnabledChangedEventHandler;
// NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements.
//
// ce.IsVisibleChanged += _overIsVisibleChangedEventHandler;View on GitHub (pinned to 81131a70a4)