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_style_namespace_declarations' is unclear #71844

Closed
vsfeedback opened this issue Jan 29, 2024 · 2 comments · Fixed by #74449
Closed

Error message for invalid 'csharp_style_namespace_declarations' is unclear #71844

vsfeedback opened this issue Jan 29, 2024 · 2 comments · Fixed by #74449
Assignees
Labels

Comments

@vsfeedback
Copy link

vsfeedback commented Jan 29, 2024

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


[severity:It bothers me. A fix would be nice]
Multiple errors thrown in Visual Studio when opening existing solution. Persists after closing and rebooting Visual Studio and rebooting Windows.

Stack traces for the three errors:

CSharpWrappingCodeRefactoringProvider encountered and error and has been disabled

System.NotSupportedException : Specified method is not supported.
   at Microsoft.CodeAnalysis.CSharp.CodeStyle.CSharpCodeStyleOptions.ParseNamespaceDeclaration(String optionString,CodeStyleOption2`1 default)
   at Microsoft.CodeAnalysis.CSharp.CodeStyle.CSharpCodeStyleOptions.<>c__DisplayClass76_2. <.cctor>b__7(String str)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key,Func`2 valueFactory)
   at Microsoft.CodeAnalysis.Options.EditorConfigValueSerializer`1.TryParseValue(String value,T& result)
   at Microsoft.CodeAnalysis.AnalyzerConfigOptionsExtensions.TryGetEditorConfigOption[T](AnalyzerConfigOptions analyzerConfigOptions,IOption2 option,T& value)
   at Microsoft.CodeAnalysis.Diagnostics.StructuredAnalyzerConfigOptions.TryGetOption[T](OptionKey2 optionKey,T& value)
   at Microsoft.CodeAnalysis.Options.Extensions.GetOption[T](IOptionsReader options,Option2`1 option,T defaultValue)
   at Microsoft.CodeAnalysis.CSharp.Formatting.CSharpSyntaxFormattingOptions.. ctor(IOptionsReader options,CSharpSyntaxFormattingOptions fallbackOptions)
   at Microsoft.CodeAnalysis.CSharp.Wrapping.CSharpSyntaxWrappingOptionsProviders.GetCSharpSyntaxWrappingOptions(IOptionsReader options,CodeActionOptions fallbackOptions)
   at async Microsoft.CodeAnalysis.Wrapping.AbstractWrappingCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)

IntroduceVariableCodeRefactoringProvider encountered and error and has been disabled

System.NotSupportedException : Specified method is not supported.
   at Microsoft.CodeAnalysis.CSharp.CodeStyle.CSharpCodeStyleOptions.ParseNamespaceDeclaration(String optionString,CodeStyleOption2`1 default)
   at Microsoft.CodeAnalysis.CSharp.CodeStyle.CSharpCodeStyleOptions.<>c__DisplayClass76_2. <.cctor>b__7(String str)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key,Func`2 valueFactory)
   at Microsoft.CodeAnalysis.Options.EditorConfigValueSerializer`1.TryParseValue(String value,T& result)
   at Microsoft.CodeAnalysis.AnalyzerConfigOptionsExtensions.TryGetEditorConfigOption[T](AnalyzerConfigOptions analyzerConfigOptions,IOption2 option,T& value)
   at Microsoft.CodeAnalysis.Diagnostics.StructuredAnalyzerConfigOptions.TryGetOption[T](OptionKey2 optionKey,T& value)
   at Microsoft.CodeAnalysis.Options.Extensions.GetOption[T](IOptionsReader options,Option2`1 option,T defaultValue)
   at Microsoft.CodeAnalysis.CSharp.Formatting.CSharpSyntaxFormattingOptions.. ctor(IOptionsReader options,CSharpSyntaxFormattingOptions fallbackOptions)
   at Microsoft.CodeAnalysis.CSharp.Formatting.CSharpSyntaxFormatting.GetFormattingOptions(IOptionsReader options,SyntaxFormattingOptions fallbackOptions)
   at Microsoft.CodeAnalysis.CodeCleanup.CodeCleanupOptionsProviders.GetCodeCleanupOptions(IOptionsReader options,LanguageServices languageServices,Nullable`1 allowImportsInHiddenRegions,CodeCleanupOptions fallbackOptions)
   at async Microsoft.CodeAnalysis.CodeCleanup.CodeCleanupOptionsProviders.GetCodeCleanupOptionsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeCleanup.CodeCleanupOptionsProviders.GetCodeCleanupOptionsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.IntroduceVariable.IntroduceVariableCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)

UseExpressionBodyCodeRefactoringProvider encountered and error and has been disabled

System.NotSupportedException : Specified method is not supported.
   at Microsoft.CodeAnalysis.CSharp.CodeStyle.CSharpCodeStyleOptions.ParseNamespaceDeclaration(String optionString,CodeStyleOption2`1 default)
   at Microsoft.CodeAnalysis.CSharp.CodeStyle.CSharpCodeStyleOptions.<>c__DisplayClass76_2. <.cctor>b__7(String str)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key,Func`2 valueFactory)
   at Microsoft.CodeAnalysis.Options.EditorConfigValueSerializer`1.TryParseValue(String value,T& result)
   at Microsoft.CodeAnalysis.AnalyzerConfigOptionsExtensions.TryGetEditorConfigOption[T](AnalyzerConfigOptions analyzerConfigOptions,IOption2 option,T& value)
   at Microsoft.CodeAnalysis.Diagnostics.StructuredAnalyzerConfigOptions.TryGetOption[T](OptionKey2 optionKey,T& value)
   at Microsoft.CodeAnalysis.Options.Extensions.GetOption[T](IOptionsReader options,Option2`1 option,T defaultValue)
   at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationOptions.. ctor(IOptionsReader options,CSharpCodeGenerationOptions fallbackOptions)
   at Microsoft.CodeAnalysis.CSharp.CodeGeneration.CSharpCodeGenerationService.GetCodeGenerationOptions(IOptionsReader options,CodeGenerationOptions fallbackOptions)
   at async Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationOptionsProviders.GetCodeGenerationOptionsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationOptionsProviders.GetCodeGenerationOptionsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CSharp.UseExpressionBody.UseExpressionBodyCodeRefactoringProvider.ComputeRefactoringsAsync(<Unknown Parameters>)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.CodeAnalysis.CodeRefactorings.CodeRefactoringService.GetRefactoringFromProviderAsync(<Unknown Parameters>)

Original Comments

Feedback Bot on 1/24/2024, 08:47 PM:

(private comment, text removed)

Wenwen Fan [MSFT] on 1/25/2024, 02:17 AM:

(private comment, text removed)

Jason Taylor on 1/28/2024, 05:24 PM:

(private comment, text removed)

Feedback Bot on 1/29/2024, 00:44 AM:

(private comment, text removed)


Original Solutions

(no solutions)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 29, 2024
@sharwell
Copy link
Member

sharwell commented Jan 29, 2024

This error occurs when .editorconfig contains a value for csharp_style_namespace_declarations which cannot be parsed:

return value switch
{
"block_scoped" => new(NamespaceDeclarationPreference.BlockScoped, notification),
"file_scoped" => new(NamespaceDeclarationPreference.FileScoped, notification),
_ => throw new NotSupportedException(),
};

This code should report a more specific error message which indicates the value which could not be parsed. For example:

csharp_style_namespace_declarations = invalid:warning

Could report an error like this:

EditorConfig option 'csharp_style_namespace_declarations' contains unrecognized value 'invalid'

This is just an example. I'm not perfectly happy with this wording, so if someone finds a better phrasing that would be fine. The format string should be usable for multiple .editorconfig parsing situations, and this is not the only location where we throw a NotSupportedException without a specific string today.

@jt-pt-dev
Copy link

Thanks Sam. That has resolved my issue.

@Cosifne Cosifne removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants