URI return values should not be strings
URI return values should not be strings
Microsoft docsDescription
This rule splits the method name into tokens based on the Pascal casing convention and checks whether each token equals "uri", "Uri", "urn", "Urn", "url", or "Url". If there's a match, the rule assumes that the method returns a uniform resource identifier (URI). A string representation of a URI is prone to parsing and encoding errors, and can lead to security vulnerabilities. The System.Uri class provides these services in a safe and secure manner.
Cause
The name of a method contains "uri", "Uri", "urn", "Urn", "url", or "Url", and the method returns a string.
By default, this rule only looks at externally visible methods, but this is configurable.
How to fix violations
To fix a violation of this rule, change the return type to a System.Uri.
Example
#pragma warning disable CA1055
// The code that's violating the rule is on this line.
#pragma warning restore CA1055When to suppress
It's safe to suppress a warning from this rule if the return value does not represent a URI.