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

AD0001 (KeyNotFoundException) from AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer #38668

Closed
Tragetaschen opened this issue Sep 12, 2019 · 8 comments

Comments

@Tragetaschen
Copy link

Version Used:
16.3.0 Preview 3.0

Steps to Reproduce:

using System.Text;

internal static class C1
{
    public const int A = 42;
}

internal class C2
{
    public int A { get; set; }
}

internal class C3
{
    public string M(C2 c2)
    {
        var result = new StringBuilder();
        switch (c2.A)
        {
            case C1.A:
                result.Append("A");
                break;
            default:
                result.Append("*");
                break;
        }
        return result.ToString();
    }
}

Expected Behavior:
No AD0001

Actual Behavior:

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Warning	AD0001	Analyzer 'Microsoft.CodeAnalysis.CSharp.RemoveUnusedParametersAndValues.CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer' threw an exception of type 'System.Collections.Generic.KeyNotFoundException' with message 'The given key was not present in the dictionary.'.	…		1	Active	Analyzer 'Microsoft.CodeAnalysis.CSharp.RemoveUnusedParametersAndValues.CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: …
IOperation: ExpressionStatement
SyntaxTree: C:\Users\…\Test.cs
SyntaxNode: result.Append("A"); [ExpressionStatementSyntax]@[319..338) (20,16)-(20,35)

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Immutable.ImmutableDictionary`2.get_Item(TKey key)
   at Microsoft.CodeAnalysis.RemoveUnusedParametersAndValues.AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.AnalyzeExpressionStatement(OperationAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteOperationAction>b__54_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
'.
@mavasani mavasani self-assigned this Sep 12, 2019
@mavasani mavasani added the Bug label Sep 12, 2019
@mavasani mavasani added this to the 16.4 milestone Sep 12, 2019
@mavasani
Copy link
Contributor

Fires when user has an invalid editorconfig option value.

@Tragetaschen
Copy link
Author

Tragetaschen commented Sep 13, 2019

Do you have a (couple of) candidates, then I can check.
I have changed

csharp_style_unused_value_expression_statement_preference = true:error

to

csharp_style_unused_value_expression_statement_preference = discard_variable:error

to make AD0001 go away. That was from a time when those settings weren't yet documented.

Is there a better way to check the contents of .editorconfig files?

@mavasani
Copy link
Contributor

Is there a better way to check the contents of .editorconfig files?

I believe @sharwell had a tracking issue to create an IDE analyzer that validates our IDE options in .editorconfig files.

@Tragetaschen
Copy link
Author

Tragetaschen commented Sep 23, 2019

#19055?

@jinujoseph jinujoseph modified the milestones: 16.4, Backlog Dec 11, 2019
@OoLunar
Copy link

OoLunar commented Feb 13, 2022

Good to know that it's an invalid editorconfig option. Are there plans to warn us which option is invalid instead of getting an unhelpful CSC KeyNotFound warning?

@CyrusNajmabadi
Copy link
Member

@jmarolf Does thsi go away now that the user can set these with the editorconfig ui? Does it tell you if you wrote things badly?

@jmarolf
Copy link
Contributor

jmarolf commented Feb 15, 2023

We don't have a mechanism to surface diagnostics in editorconfig yet if you manually edit the file, however if these options are set via the UI you should be "protected" from setting them to invalid values.

@CyrusNajmabadi
Copy link
Member

Closing out due to lack of hits.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants