dotnet / roslyn-analyzers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CA2208 - False positive for specific text in ArgumentException parameter

vsfeedback opened this issue · comments

This issue has been moved from a ticket on Developer Community.


I got CA2208 message, which doesn't make sense. I was able to reproduce it:

Bb9c30e593e3d4a32b5da5f6a7a76df0a638490506966595059_20240418-172455-image

Source code:

namespace ConsoleApp16;

internal class Program
{
    static void Main()
    {
        Test([1, 2, 3]);
    }

    static void Test(byte[] data)
    {
        throw new ArgumentException("data.Length of encrypted data must be completely divisible by 8.");
    }
}

The message only appears if argument of ArgumentException constructor starts with "data.Length". If I simply remove "data", then message disappears:

B983bb8a09070416b8fd6f616d3f63180638490509238538462_20240418-172843-image

It seems static analyzer checks for parameter name matching starting value of string? Note: ArgumentException has different order of parameters in overload, where both text and parameter name are given, as e.g. ArgumentOutOfRangeException. I guess there is a bug, which assume it's must be first and text is used to determine whenever it's parameter name to show the message.

The suggested fix is also broken, it tries to put whole string into nameof(...), that clearly wouldn't work:

B32559a8371b14bd4bf3fe30946b1db42638490512214917687_20240418-173341-image


Original Comments

Feedback Bot on 4/19/2024, 00:31 AM:

(private comment, text removed)


Original Solutions

(no solutions)

I can't seem to reproduce this. Which .NET version are you targeting?

@CollinAlpert, it was .Net 8.0. But I can't reproduce it anymore either. It seems the issue was fixed (I just installed Version 17.9.6 update for my VS2022 x64) or it was something local. Close the subject please.