dotnet/wpf · error · InvalidOperationException
Operation cannot be performed.
Error message
Operation cannot be performed.
What it means
IValueProvider.SetValue parses the string with GetIPAddressFromString; if the string is not a valid IPv4 address, the proxy throws InvalidOperationException('Operation cannot be performed') instead of sending IPM_SETADDRESS. Only valid 4-octet IPv4 values are accepted.
Solutions
- Pass a valid dotted-quad IPv4 string (e.g. "192.168.0.1") with exactly 4 octets in 0-255
- Pre-validate the string with IPAddress.TryParse before calling SetValue
- Catch InvalidOperationException and report the invalid input to the caller
- Trim/handle whitespace and ensure the test data has no typos
Example fix
// before
valuePattern.SetValue(userInput);
// after
if (System.Net.IPAddress.TryParse(userInput, out var ip) && ip.AddressFamily == AddressFamily.InterNetwork && userInput.Split('.').Length == 4)
{
valuePattern.SetValue(userInput);
}
else
{
throw new FormatException($"'{userInput}' is not a valid IPv4 address.");
} Defensive patterns
Strategy: validation
Validate before calling
bool valid = System.Net.IPAddress.TryParse(val, out var ip) && val.Split('.').Length == 4 && ip.AddressFamily == AddressFamily.InterNetwork; Try / catch
try { valuePattern.SetValue(val); }
catch (InvalidOperationException) { /* invalid IPv4 string; report or fix input */ } Prevention
- Pre-validate with IPAddress.TryParse and require 4 octets
- Reject IPv6 for SysIPAddress32 controls
- Trim whitespace from user/config input
- Use canonical dotted-quad strings in test data
When it happens
Trigger: Calling IValueProvider.SetValue with strings like "abc", "999.1.1.1", "1.2.3" (3 octets), or empty string; GetIPAddressFromString returns null so control reaches the throw at the end of SetValue.
Common situations: Passing IPv6 addresses to an IPv4-only SysIPAddress32 control; whitespace/typos in test data; localized or malformed input from a config file.
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
- ' ' is not a valid value for this control.
- Element is not enabled.
- SR.GetResourceString(reason)
- SR.OperationCannotBePerformed
- throw new…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d25473018f02c282.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs:143
byte[] abOctet = ipAddress.GetAddressBytes();
if (abOctet.Length == 4)
{
uint ipV4 = 0;
for (int iPos = 0; iPos < 4; iPos++)
{
ipV4 = (ipV4 << 8) + abOctet[iPos];
}
// no return result for this message, so if it get sent it must have succeeded
Misc.ProxySendMessage(_hwnd, NativeMethods.IPM_SETADDRESS, IntPtr.Zero, (IntPtr)unchecked((int)ipV4));
return;
}
}
// this was no a valid IP address
throw new InvalidOperationException (SR.OperationCannotBePerformed);
}
// Request to get the value that this UI element is representing as a string
string IValueProvider.Value
{
get
{
return Misc.ProxyGetText(_hwnd, IP_ADDRESS_STRING_LENGTH);
}
}
bool IValueProvider.IsReadOnly
{
get
{
return !Misc.IsEnabled(_hwnd);
}View on GitHub (pinned to 81131a70a4)