dotnet/wpf · error · NotSupportedException
SR.Unsupported_MouseAction (mouseActionToken)
Error message
SR.Unsupported_MouseAction (mouseActionToken)
What it means
MouseActionConverter.ConvertFrom parses a string into a MouseAction; a token that matches none of the known names (LeftClick, RightClick, MiddleClick, WheelClick, LeftDoubleClick, RightDoubleClick, MiddleDoubleClick) throws NotSupportedException with SR.Unsupported_MouseAction. Matching is case-insensitive but the text must equal one of these tokens exactly.
Solutions
- Use one of the exact token names: LeftClick, RightClick, MiddleClick, WheelClick, LeftDoubleClick, RightDoubleClick, MiddleDoubleClick (case-insensitive)
- Fix typos in XAML, e.g. Gesture="LeftClick" instead of "Click"
- Pre-validate the string against the token list and show a friendly message
Example fix
// before <MouseBinding Gesture="Click" Command="..."/> // after <MouseBinding Gesture="LeftClick" Command="..."/>
Defensive patterns
Strategy: validation
Validate before calling
string[] valid = {"LeftClick","RightClick","MiddleClick","WheelClick","LeftDoubleClick","RightDoubleClick","MiddleDoubleClick"};
bool ok = valid.Contains(s, StringComparer.OrdinalIgnoreCase); Try / catch
try { action = (MouseAction)converter.ConvertFrom(s); } catch (NotSupportedException ex) { /* unknown MouseAction token */ } Prevention
- Use exact canonical token names in XAML and config (case-insensitive)
- Remember 'Click' alone is invalid — use 'LeftClick'
- Validate user-entered action strings against the token list
When it happens
Trigger: Calling ConvertFrom with strings like "Click", "LeftClick2", "DoubleClick", or localized/translated names; also XAML attribute values with typos.
Common situations: XAML MouseBinding Gesture="Click" (missing the Left prefix) or parsing user-supplied shortcut strings that don't match the canonical token names.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- InvalidEnumArgumentException(nameof(value)…
- SR.Format(SR.ParserCannotConvertPropertyValue, "Value"…
- SR.MultiBindingHasNoConverter
- Animation_ChildMustBeKeyFrame
- Animation_ChildMustBeKeyFrame
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/4ded541f49d3642c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/MouseActionConverter.cs:70
/// <returns>A <see cref="MouseAction"/> representing the <see langword="string"/> specified by <paramref name="source"/>.</returns>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object source)
{
if (source is not string mouseAction)
throw GetConvertFromException(source);
ReadOnlySpan<char> mouseActionToken = mouseAction.AsSpan().Trim();
return mouseActionToken switch
{
_ when mouseActionToken.IsEmpty => MouseAction.None, // Special casing as produced by "ConvertTo"
_ when mouseActionToken.Equals("None", StringComparison.OrdinalIgnoreCase) => MouseAction.None,
_ when mouseActionToken.Equals("LeftClick", StringComparison.OrdinalIgnoreCase) => MouseAction.LeftClick,
_ when mouseActionToken.Equals("RightClick", StringComparison.OrdinalIgnoreCase) => MouseAction.RightClick,
_ when mouseActionToken.Equals("MiddleClick", StringComparison.OrdinalIgnoreCase) => MouseAction.MiddleClick,
_ when mouseActionToken.Equals("WheelClick", StringComparison.OrdinalIgnoreCase) => MouseAction.WheelClick,
_ when mouseActionToken.Equals("LeftDoubleClick", StringComparison.OrdinalIgnoreCase) => MouseAction.LeftDoubleClick,
_ when mouseActionToken.Equals("RightDoubleClick", StringComparison.OrdinalIgnoreCase) => MouseAction.RightDoubleClick,
_ when mouseActionToken.Equals("MiddleDoubleClick", StringComparison.OrdinalIgnoreCase) => MouseAction.MiddleDoubleClick,
_ => throw new NotSupportedException(SR.Format(SR.Unsupported_MouseAction, mouseActionToken.ToString()))
};
}
/// <summary>
/// Converts a <paramref name="value"/> of <see cref="MouseAction"/> to its <see langword="string"/> represensation.
/// </summary>
/// <param name="context">Serialization Context</param>
/// <param name="culture">Culture Info</param>
/// <param name="value">MouseAction value </param>
/// <param name="destinationType">Type to Convert</param>
/// <returns>A <see langword="string"/> representing the <see cref="MouseAction"/> specified by <paramref name="value"/>.</returns>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
ArgumentNullException.ThrowIfNull(destinationType);
if (value is null || destinationType != typeof(string))
throw GetConvertToException(value, destinationType);
View on GitHub (pinned to 81131a70a4)