C# – Validate an IP address

Use IPAddress.Parse() to parse an IP address from a string. This handles both IPv4 and IPv6 addresses and throws an exception if the string can’t be parsed into a valid IP address. Here’s an example: This outputs the following: Use IPAddress.TryParse() if you don’t want exceptions to be thrown. It returns false if the string … Read more

Error: Attribute constructor has an invalid parameter type

Problem When you try to pass in an attribute constructor parameter to a custom attribute, you get one of the following compiler errors: Error CS0181 Attribute constructor parameter has type ‘Color’ which is not a valid attribute parameter type Error CS0655 ‘Color’ is not a valid named attribute argument because it is not a valid … Read more