roslyn: Wrong IDE0130 message "Namespace 'Foo' does not match folder structure, expected 'Foo'"

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


[regression] [worked-in:16.11?] I have a .NET 5.0 project which has app which has default namespace ‘Microsoft.BigSolutionGenerator’. Each source file shows

IDE0130: "Namespace "Microsoft.BigSolutionGenerator" does not match folder structure, expected "Microsoft.BigSolutionGenerator."

… although it already has namespace Microsoft.BigSolutionGenerator. Lightbulb offers to replace namespace with Microsoft.BigSolutionGenerator.Microsoft.BigSolutionGenerator

! [image.png] (https://aka.ms/dc/image?name=B2b8b22d62a694eb6acf89007e304b951637624074571776408_20210720-125057-image.png&tid=2b8b22d62a694eb6acf89007e304b951637624074571776408)


Original Comments

Feedback Bot on 7/20/2021, 11:41 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Feedback Bot on 7/21/2021, 10:09 AM:

Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2019#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.


Original Solutions

(no solutions)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 18 (6 by maintainers)

Most upvoted comments

I’m also having this issue with a .NET 6 project. In Visual Studio the code fix works fine, but when triggered from dotnet format I do get the aforementioned exception. Example solution can be found here.

Exception that occurs when running dotnet format on the solution:

Unhandled exception: System.NotSupportedException: Changing document properties is not supported
   at Microsoft.CodeAnalysis.Workspace.CheckAllowedProjectChanges(ProjectChanges projectChanges)
   at Microsoft.CodeAnalysis.Workspace.CheckAllowedSolutionChanges(SolutionChanges solutionChanges)
   at Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.TryApplyChanges(Solution newSolution)
   at Microsoft.CodeAnalysis.Tools.CodeFormatter.FormatWorkspaceAsync(FormatOptions formatOptions, ILogger logger, CancellationToken cancellationToken, String binaryLogPath)
   at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.FormatAsync(FormatOptions formatOptions, ILogger`1 logger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

I still have the issue in 5.0.402, so it is not fixed. @edwiles I did a global suppression just for the root namespace, which solved it for the time being.

[assembly: SuppressMessage("Style", "IDE0130:Namespace does not match folder structure", Justification = "It cannot handle items in root namespace", Scope = "namespace", Target = "~N:MyCompany.MyApp")]```

I can confirm that image 5.0.303 works

We face the same issue in our .NET 5 project as well using the mcr.microsoft.com/dotnet/sdk:5.0 base image to build in docker.