dotnet/wpf · error · InvalidOperationException
SR.Touch_DeviceAlreadyActivated
Error message
SR.Touch_DeviceAlreadyActivated
What it means
TouchDevice.Activate registers the touch device with the input system (AddActiveDevice, AttachTouchDevice, Synchronize). A device may only be activated once; if _isActive is already true, Activate throws InvalidOperationException(Touch_DeviceAlreadyActivated). This is a state-machine guard: double activation would corrupt the active-device list and event routing.
Solutions
- Track activation state in your device wrapper and call Activate() only when it has never been activated or after a successful Deactivate().
- Structure the provider so Activate is invoked exactly once from a single lifecycle hook (e.g. OnTabletAdded), not from every input report.
- Wrap the call so re-activation is a no-op instead of an exception path.
Example fix
// before
protected override void OnCreated()
{
Activate();
}
protected override void OnEnabled() // may fire after OnCreated
{
Activate(); // InvalidOperationException: already activated
}
// after
private bool _activated;
private void EnsureActivated()
{
if (!_activated)
{
Activate();
_activated = true;
}
} Defensive patterns
Strategy: validation
Validate before calling
if (device.IsActive) return; // skip Activate when already active
Try / catch
try { device.Activate(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("activated"))
{
// already active — treat as success
} Prevention
- Call Activate exactly once from a single lifecycle hook.
- Mirror every Activate with a Deactivate and track it with your own flag.
- Never activate from per-input-report callbacks.
When it happens
Trigger: Calling Activate() (from a TouchDevice subclass, e.g. a custom stylus/touch provider) a second time without an intervening Deactivate(); calling Activate from both a touchdown handler and an initialization path; re-activating after a reset that did not actually clear _isActive.
Common situations: Custom touch/stylus integration code (e.g. simulated touch drivers, Windows Ink interop) that activates the device in multiple lifecycle callbacks; re-entrancy when the same device is reported by several input reports; test harnesses activating fixtures repeatedly.
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.Touch_DeviceNotActivated
- SR.Manipulation_ManipulationNotEnabled
- Animation_Invalid_DefaultValue
- ArgumentOutOfRangeException(nameof(value))
- ArgumentOutOfRangeException(nameof(value))
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/28bb8a5a9b6e0305.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TouchDevice.cs:694
_reevaluateOver = null;
OnHitTestInvalidatedAsync(this, EventArgs.Empty);
}
bool handled = RaiseTouchUp();
_isDown = false;
UpdateDirectlyOver(isSynchronize: false);
OnUpdated();
Touch.ReportFrame();
return handled;
}
protected void Activate()
{
if (_isActive)
{
throw new InvalidOperationException(SR.Touch_DeviceAlreadyActivated);
}
PromotingToManipulation = false;
AddActiveDevice(this);
AttachTouchDevice();
Synchronize();
if (_activeDevices.Count == 1)
{
_isPrimary = true;
}
_isActive = true;
if (Activated != null)
{
Activated(this, EventArgs.Empty);
}View on GitHub (pinned to 81131a70a4)