Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CA2208 - False positive for specific text in ArgumentException parameter #7300

Open
vsfeedback opened this issue Apr 19, 2024 · 2 comments
Open

Comments

@vsfeedback
Copy link

vsfeedback commented Apr 19, 2024

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)

@CollinAlpert
Copy link
Contributor

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

@sinatrocious
Copy link

sinatrocious commented May 13, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants