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

Error message for invalid csharp_using_directive_placement is not clear #49407

Open
vsfeedback opened this issue Nov 16, 2020 · 7 comments
Open
Labels
Area-Analyzers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@vsfeedback
Copy link

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


[severity:It's more difficult to complete my work]
Hi, when I run a CodeAnalysis on my . Net5 solution I see 72 warnings in the Error List (I think one for every file). All the warnings are AD0001:

Severity	Code	Description	Project	File	Line	Suppression State
Warning	AD0001	Analyzer 'Microsoft.CodeAnalysis.CSharp.MisplacedUsingDirectives.MisplacedUsingDirectivesDiagnosticAnalyzer' threw an exception of type 'System.NotSupportedException' with message 'Specified method is not supported.'.
Exception occurred with following context:
Compilation: Translator.Core
SyntaxTree: C:\Users\wvl\source\repos\KasparInternal.Tools.FlutterTranslationHelper\Translator.Core\TypeBuilder\EntryTypeBuilder.LanguagePropertyBuilder.cs
SyntaxNode: using System; using System.Linq ... [CompilationUnitSyntax]@[20..6103) (2,0)-(139,0)

System.NotSupportedException: Specified method is not supported.
   at Microsoft.CodeAnalysis.CSharp.CodeStyle.CSharpCodeStyleOptions.ParseUsingDirectivesPlacement(String optionString, CodeStyleOption2`1 default)
   at Microsoft.CodeAnalysis.CSharp.CodeStyle.CSharpCodeStyleOptions.<>c.<.cctor>b__46_9(String s)
   at Microsoft.CodeAnalysis.Options.EditorConfigStorageLocation`1.TryGetOption(String value, Type type, T& result)
   at Microsoft.CodeAnalysis.AnalyzerConfigOptionsExtensions.TryGetEditorConfigOption[T](AnalyzerConfigOptions analyzerConfigOptions, IOption option, Boolean useDefaultIfMissing, T& value)
   at Microsoft.CodeAnalysis.AnalyzerConfigOptionsExtensions.TryGetEditorConfigOption[T](AnalyzerConfigOptions analyzerConfigOptions, IOption option, T& value)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerHelper. <GetOptionAsync>d__24`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerHelper.GetOption[T](AnalyzerOptions analyzerOptions, ILanguageSpecificOption`1 option, SyntaxTree syntaxTree, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CSharp.MisplacedUsingDirectives.MisplacedUsingDirectivesDiagnosticAnalyzer.AnalyzeCompilationUnitNode(SyntaxNodeAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__62`1. <ExecuteSyntaxNodeAction>b__62_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----

Suppress the following diagnostics to disable this analyzer: IDE0065	Translator.Core		1	Active


Original Comments

(no comments)


Original Solutions

(no solutions)

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 16, 2020
@jinujoseph jinujoseph added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 17, 2020
@jinujoseph jinujoseph added this to the 16.9 milestone Nov 17, 2020
@CyrusNajmabadi
Copy link
Member

You have an editorconfig value for csharp_using_directive_placement that is not inside_namespace or outside_namespace.

@CyrusNajmabadi
Copy link
Member

@sharwell @jinujoseph do we have a tracking bug about making these errors easier to diagnose? I would like to dupe this against that. It's def a probem that we just throw new NotSupportedException() without any sort of clear message to the user as to what the issue is.

@jinujoseph
Copy link
Contributor

@JoeRobich thoughts ?

@JoeRobich
Copy link
Member

We should remove throwing NotSupported when parsing the users editorconfig value string. Other parsing methods return the @default value when the string contains an unexpected value.

@sharwell
Copy link
Member

@CyrusNajmabadi We have #19055 and #37347

@jinujoseph jinujoseph modified the milestones: 16.9, 16.10 Mar 28, 2021
@jinujoseph jinujoseph modified the milestones: 16.10, Backlog Jul 16, 2021
@CyrusNajmabadi
Copy link
Member

Closing out as covered by other analyzers.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2022
@sharwell sharwell reopened this Mar 14, 2023
@sharwell
Copy link
Member

From #67299:

In the above case, the user has the following in their .editorconfig file:

# usings outside namespace
csharp_using_directive_placement = true

This is producing an exception in the following parsing code:

return value switch
{
"inside_namespace" => new CodeStyleOption2<AddImportPlacement>(AddImportPlacement.InsideNamespace, notification),
"outside_namespace" => new CodeStyleOption2<AddImportPlacement>(AddImportPlacement.OutsideNamespace, notification),
_ => throw new NotSupportedException(),
};

The parsing code should be updated to provide a more detailed (actionable) error message for users.

@sharwell sharwell added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. labels Mar 14, 2023
@sharwell sharwell changed the title CodeAnalysis method NotSupportedException Error message for invalid csharp_using_directive_placement is not clear Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
None yet
Development

No branches or pull requests

6 participants