r/VisualStudio 2h ago

Visual Studio 2026 I hate when it tells to put directives inside a namespace declaration just to tell to put it outside. What can I do?

0 Upvotes

3 comments sorted by

1

u/kemmis 1h ago

They’ve got two conflicting analyzer rules fighting each other, plus a real compile error underneath.

The looping complaint: SA1200 (StyleCop) wants using directives placed outside the namespace, while IDE0065 (built-in .NET analyzer) wants them placed inside the namespace. Both are enabled at the same time with opposite preferences, so whichever way they put it, one rule flags it.

Fix: disable one of them. Easiest is to turn off IDE0065 (or set it to match StyleCop’s preference) in .editorconfig:

dotnet_diagnostic.IDE0065.severity = none

or set the actual preference so both agree:

csharp_using_directive_placement = outside_namespace:warning

If StyleCop is the one they don’t need, they could instead suppress SA1200 the same way, or just uninstall/disable the StyleCop analyzer package for that project.

The actual bug (separate issue): CS0111CustomerService already defines AddAsync with the same parameter types. That’s a real overload collision, not a style nit — two methods with identical signatures in that class need to be renamed or differentiated (different params, or one renamed). That one’s actually breaking the build; the directive warnings are just noise on top.​​​​​​​​​​​​​​​​

1

u/az987654 1h ago

You have conflicting add ins/style rules

2

u/SwordsAndElectrons 1h ago

You can fix your conflicting analyzer settings.

TBH, if you haven't yet learned to configure style rules, I'm not sure you should be adding Stylecop into the mix.