Exclude FxCop DoNotPassLiteralsAsLocalizedParameters errors from creating an exception instance or localize exception messages

I get a DoNotPassLiteralsAsLocalizedParameters FxCop violation for both exception lines in the method below:

public bool IsPageAccessible(string url, string documentId) {
    if (url == null) {
        throw new ArgumentNullException("url", @"url must not be null, use string.Empty if you don't care what the url is.");
    }

    if (documentId == null) {
        throw new ArgumentNullException("documentId", "documentId must not be null, use string.Empty if you don't care what the documentId is.");
    }
    return true;
}

It means:

fxcop Globalization # CA1303 String literals embedded in source code are difficult to localize. Avoid passing string literals as arguments in cases where a localized string is usually expected. Most localized applications, for example, must localize string arguments that are passed to exception constructors. When creating an instance of Exception, therefore, the resulting row argument from the row table is larger than the corresponding string literal.

Reasoning:

. . , API, . .

:

  • ? ?
  • FxCop ? API. , , . .
  • , ?
+3
1

, , , Visual Studio , lingua franca - .

fxcop, . .

, , SuppressMessage:

[SuppressMessage("Microsoft.Globalization", 
                 "CA1303:DoNotPassLiteralsAsLocalizedParameters", 
                 Justification="Exception are not localized")]
public bool IsPageAccessible(string url, string documentId) {
  if (url == null) {
    throw new ArgumentNullException("url", @"url must not be null, use string.Empty if you don't care what the url is.");
  }

  if (documentId == null) {
    throw new ArgumentNullException("documentId", "documentId must not be null, use string.Empty if you don't care what the documentId is.");
  }
  return true;
}

fxcop, .

+1

Source: https://habr.com/ru/post/1762674/


All Articles