{"record":{"id":"d25473018f02c282","repo":"dotnet/wpf","slug":"operation-cannot-be-performed-windowsipaddress","errorCode":null,"errorMessage":"Operation cannot be performed.","messagePattern":"Operation cannot be performed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs","lineNumber":143,"sourceCode":"                byte[] abOctet = ipAddress.GetAddressBytes();\n\n                if (abOctet.Length == 4)\n                {\n                    uint ipV4 = 0;\n\n                    for (int iPos = 0; iPos < 4; iPos++)\n                    {\n                        ipV4 = (ipV4 << 8) + abOctet[iPos];\n                    }\n\n                    // no return result for this message, so if it get sent it must have succeeded\n                    Misc.ProxySendMessage(_hwnd, NativeMethods.IPM_SETADDRESS, IntPtr.Zero, (IntPtr)unchecked((int)ipV4));\n                    return;\n                }\n            }\n\n            // this was no a valid IP address\n            throw new InvalidOperationException (SR.OperationCannotBePerformed);\n        }\n\n\n        // Request to get the value that this UI element is representing as a string\n        string IValueProvider.Value\n        {\n            get\n            {\n                return Misc.ProxyGetText(_hwnd, IP_ADDRESS_STRING_LENGTH);\n            }\n        }\n\n        bool IValueProvider.IsReadOnly\n        {\n            get\n            {\n                return !Misc.IsEnabled(_hwnd);\n            }","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsIPAddress.cs#L125-L161","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing IPv6 addresses to an IPv4-only SysIPAddress32 control; whitespace/typos in test data; localized or malformed input from a config file.","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"],"exampleFix":"// before\nvaluePattern.SetValue(userInput);\n// after\nif (System.Net.IPAddress.TryParse(userInput, out var ip) && ip.AddressFamily == AddressFamily.InterNetwork && userInput.Split('.').Length == 4)\n{\n    valuePattern.SetValue(userInput);\n}\nelse\n{\n    throw new FormatException($\"'{userInput}' is not a valid IPv4 address.\");\n}","handlingStrategy":"validation","validationCode":"bool valid = System.Net.IPAddress.TryParse(val, out var ip) && val.Split('.').Length == 4 && ip.AddressFamily == AddressFamily.InterNetwork;","typeGuard":null,"tryCatchPattern":"try { valuePattern.SetValue(val); }\ncatch (InvalidOperationException) { /* invalid IPv4 string; report or fix input */ }","preventionTips":["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"],"tags":["uiautomation","invalid-ip-address","setvalue","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}