Skip to content

Bugfix 918#930

Merged
SteveDunn merged 5 commits into
mainfrom
bugfix-918
May 5, 2026
Merged

Bugfix 918#930
SteveDunn merged 5 commits into
mainfrom
bugfix-918

Conversation

@SteveDunn

Copy link
Copy Markdown
Owner

Fixes #918

SteveDunn and others added 5 commits May 5, 2026 06:55
When an assembly name starts with a digit (e.g. '1ConsoleApp'), the
generated VogenTypesFactory, BSON registration class, and OpenAPI
mapping class were placed in an invalid namespace/identifier.

Two-part fix:

1. ProjectName.FromAssemblyName now prepends '_' if the sanitised name
   starts with a digit, preventing invalid C# identifiers.

2. ValueObjectGenerator pipes the MSBuild 'RootNamespace' property
   (via AnalyzerConfigOptionsProvider) through the incremental pipeline.
   All three affected generators — GenerateCodeForSystemTextJsonConverterFactories,
   GenerateCodeForOpenApiSchemaCustomization, and GenerateCodeForBsonSerializers —
   now call ProjectName.FromRootNamespaceOrAssemblyName, which prefers the
   explicit RootNamespace over the (sanitised) assembly name.

   This means a project with AssemblyName='1ConsoleApp' and
   RootNamespace='OneConsoleApp' produces 'namespace OneConsoleApp'
   as expected.

Adds samples/1MyProg as a repro project.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…RootNamespace)

- ProjectBuilder: add _buildProperties dict, WithBuildProperty method, wire
  TestAnalyzerConfigOptionsProvider into the CSharpGeneratorDriver via
  WithUpdatedAnalyzerConfigOptions so build properties reach the generator
- SnapshotRunner: add WithBuildProperty fluent method, forward to ProjectBuilder
- New test Bug918_AssemblyNameStartingWithDigit: two tests covering the digit-
  prefix guard (_1MyProject) and RootNamespace override (OneProject)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A RootNamespace value like 'My-Project' or '1Foo' would otherwise
produce an invalid C# identifier.  Extract a private Normalise()
helper and route both paths through it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SteveDunn SteveDunn merged commit d42b806 into main May 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid namespace generated when assembly name starts with a number

1 participant