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

'AvoidConstArraysFixer' encountered an error and has been disabled. #71042

Closed
vsfeedback opened this issue Nov 20, 2023 · 2 comments · Fixed by #71044
Closed

'AvoidConstArraysFixer' encountered an error and has been disabled. #71042

vsfeedback opened this issue Nov 20, 2023 · 2 comments · Fixed by #71044
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@vsfeedback
Copy link

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


Visual Studio 2022 is recommending that I use CA1861 (Extract to static readonly field) for all instances of [InlineData(new int[] {...})] in the code below. However, when I attempt to follow this suggestion, it results in an error.

    [Theory]
    [InlineData(new int[] { 1, 2, 4, 4, 4, 5, 6 }, 4, 2)]
    [InlineData(new int[] { 1, 2, 3, 4, 5, 6, 7 }, 3, 2)]
    [InlineData(new int[] { 1, 1, 1, 1, 1, 1, 1 }, 1, 0)]
    [InlineData(new int[] { 1, 2, 3, 4, 5, 6, 7 }, 8, -1)]
    [InlineData(new int[] { 7 }, 7, 0)]
    [InlineData(new int[] { }, 5, -1)]
    public void BinarySearchFirst_ShouldFindCorrectIndex(int[] nums, int target, int expected)
    {
        // Arrange & Act
        int result = Day01.BinarySearchFirst(nums, target);

// Assert
        result. ShouldBe(expected);
    }

Here are the stack trace:

System.NullReferenceException : Object reference not set to an instance of an object.
at async Microsoft.NetCore.Analyzers.Runtime.AvoidConstArraysFixer.ExtractConstArrayAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.NetCore.Analyzers.Runtime.AvoidConstArraysFixer.<>c__DisplayClass5_0. b__0()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetChangedSolutionAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.PreviewChangesSuggestedAction.CreateAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.GetPreviewChangesFlavorAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.CreateAllFlavorsAsync()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsyncT


Original Comments

Feedback Bot on 11/19/2023, 08:33 PM:

(private comment, text removed)


Original Solutions

(no solutions)

@tmat
Copy link
Member

tmat commented Nov 30, 2023

None of these make sense for arrays in custom attributes:
image

@mavasani
Copy link
Contributor

mavasani commented Dec 1, 2023

CA1861 false positive has been fixed with dotnet/roslyn-analyzers#7044
Moving to Roslyn repo for fixing the incorrect Introduce constant refactoring offerings

@mavasani mavasani transferred this issue from dotnet/roslyn-analyzers Dec 1, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
3 participants