Skip to content

MA0185 False-positive with int? #994

@dmitriy-maksimov-wd

Description

@dmitriy-maksimov-wd

Version of the Meziantou.Analyzer NuGet package

2.0.295

Rule Identifier

MA0185

Target Framework

net10.0

C# Language version

C# 14

Description

I'm getting false positive error

0>Program.cs(10,14): Error MA0185 : Simplify string.Create when all parameters are culture invariant (https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0185.md)

Changing to int n (non-nullable) doesn't trigger the rule.

If I change to interpolated string, I'm getting a different warning

MA0076 - Do not use implicit culture-sensitive ToString in interpolated strings

Reproduction Steps

Minimal code:

class Program
{
	static void Main(string[] args)
	{
		int? n = 42;
		var s = string.Create(CultureInfo.InvariantCulture, $@"/v{n}");
		Console.WriteLine(s);
	}
}

Other information

No response

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions