Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 15, 2025

Assembly names containing dashes (e.g., tunit50-test) were causing compilation errors when using [Before(Assembly)] attributes due to invalid C# variable names being generated in the source code.

Problem

The source generator was only sanitizing dots (.) but not dashes (-) when creating C# variable names from assembly names. This resulted in invalid generated code like:

var tunit50-test_assembly = typeof(SomeType).Assembly;  // Invalid C# identifier

Which caused compilation errors:

error CS1002: ; expected
error CS0818: Implicitly-typed variables must be initialized
error CS0103: The name 'test_assembly' does not exist in the current context

Solution

Added .Replace("-", "_") to the existing sanitization chains in HookMetadataGenerator.cs at two key locations:

  1. Line 470: Assembly variable declaration in GenerateStaticConstructor
  2. Line 767: Assembly variable construction in GenerateAssemblyHookListPopulation

Now assembly names are properly sanitized to generate valid C# identifiers:

var tunit50_test_assembly = typeof(SomeType).Assembly;  // Valid C# identifier

Testing

  • ✅ All existing source generator tests pass (178 succeeded, 0 failed)
  • ✅ Public API tests confirm no breaking changes (6 succeeded, 0 failed)
  • ✅ Manual verification with test project using assembly name test-assembly-with-dashes
  • ✅ Added integration test to document the fix

The changes are minimal and surgical, following the existing pattern used elsewhere in the codebase for sanitizing names (e.g., in DataSourceHelpersGenerator.cs).

Fixes #2919.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits August 15, 2025 16:03
…g variable names

Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
Co-authored-by: thomhurst <30480171+thomhurst@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [Before(Assembly)] and assembly names with dashes Fix assembly names with dashes in Before(Assembly) hooks source generation Aug 15, 2025
@Copilot Copilot AI requested a review from thomhurst August 15, 2025 16:08
Copilot finished work on behalf of thomhurst August 15, 2025 16:08
@thomhurst thomhurst marked this pull request as ready for review August 15, 2025 16:11
@Copilot Copilot AI temporarily deployed to Pull Requests August 15, 2025 16:11 Inactive
@Copilot Copilot AI temporarily deployed to Pull Requests August 15, 2025 16:11 Inactive
@Copilot Copilot AI temporarily deployed to Pull Requests August 15, 2025 16:11 Inactive
@thomhurst thomhurst merged commit c1e9c02 into main Aug 15, 2025
9 of 15 checks passed
@thomhurst thomhurst deleted the copilot/fix-2919 branch August 15, 2025 20:13
This was referenced Aug 20, 2025
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.

[Before(Assembly)] and assembly names with dashes
2 participants