You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding an assembly attribute to a SourceFileTemplate moves its usings out of the namespace, so a relative using like Models stops resolving (CS0246) #196
With no attributes, the usings go inside the file-scoped namespace.
With attributes, the usings go at compilation-unit level, before the namespace.
C# resolves a using differently in those two places. Inside namespace Contoso.Widgets;, using Models; binds to Contoso.Widgets.Models (or Contoso.Models). At top level it only looks in the global namespace. So adding one unrelated [assembly: …] attribute changes what every using in the file binds to.
This fails with CS0246: The type or namespace name 'Models' could not be found, and Widget is not found either. Both versions were compiled with the .NET 10 SDK.
The error is the better outcome. If a global namespace with the same name exists, the using silently binds to that namespace instead. Nothing on SourceFileTemplate says that Usings resolve differently once Attributes is set. The <remarks> on AddSourceFile explain the ordering but not this consequence, and #143/#148 did not discuss it.
Suggested fix / acceptance criteria
At minimum, document on SourceFileTemplate.Usings and AddSourceFile that once Attributes is non-empty, usings are written outside the namespace and must be fully qualified.
Better, make the binding independent of whether attributes are present. Two options:
Add a separate collection for usings that belong outside the namespace, and keep Usings inside it.
Priority: Medium. A single [assembly: …] attribute silently changes how every using in the generated file binds. The usual result is a compile error (CS0246). The worse case is a quiet rebind to a same-named global namespace. There is a workaround: write fully qualified usings.
Activity
matt-edmondson commentedon Nov 10, 2026
Triage
[assembly: …]attribute silently changes how every using in the generated file binds. The usual result is a compile error (CS0246). The worse case is a quiet rebind to a same-named global namespace. There is a workaround: write fully qualified usings.SourceFileTemplate/AddSourceFilelayout (CodeBlocker/Templates/SourceFileTemplate.cs), which is the code changed in SourceFileTemplate with Attributes renders a file that doesn't compile:[assembly: X]lands above the usings (CS1529) or outside the namespace the usings are in (CS0246) #143/Write a source file's global attributes after its usings [patch] #148.using ;[patch] #191 and Skip blank entries in type and member lists instead of writing broken syntax [patch] #200 touch using and list handling but not where usings are placed.Usingsinside the namespace and requiring file-level attributes to be fully qualified is the smaller change, and SourceFileTemplate with Attributes renders a file that doesn't compile:[assembly: X]lands above the usings (CS1529) or outside the namespace the usings are in (CS0246) #143 already listed it as an alternative. Whichever is chosen, add the compile-both-ways test from the acceptance criteria. If a behaviour change is too disruptive for a patch release, ship the doc-only fix first.Generated by Claude Code