All rules
CA2241Usage Enabled by default: As suggestion

Provide correct arguments to formatting methods

Provide correct arguments to formatting methods

Microsoft docs

Description

The arguments to methods such as System.Console.WriteLine, System.Console.Write, and System.String.Format consist of a format string followed by several System.Object instances. The format string consists of text and embedded format items of the form {index[,alignment][:formatString]}. 'index' is a zero-based integer that indicates which of the objects to format. If an object does not have a corresponding index in the format string, the object is ignored. If the object specified by 'index' does not exist, a System.FormatException is thrown at runtime.

Cause

The format string argument passed to a method such as System.Console.WriteLine, System.Console.Write, or System.String.Format does not contain a format item that corresponds to each object argument, or vice versa.

By default, this rule only analyzes calls to the three methods mentioned previously, but this is configurable.

How to fix violations

To fix a violation of this rule, provide a format item for each object argument and provide an object argument for each format item.

When to suppress

Do not suppress a warning from this rule.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0