Repository navigation
Drop invalid characters from namespaces built from output folder names - #39386
Merged
AndriySvyryd merged 1 commit intoOct 22, 2026
Merged
Conversation
Scaffold and dbcontext optimize used the folder names as is, so a folder with a space or a dash gave a namespace that doesnt compile. Now they go through the same helper as migrations. Fixes dotnet#24607
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The scaffolding regression test does not verify the sanitized namespace emitted in generated entity files.
No open issues 🎉
What changed in this PR
This pull request sanitizes namespaces derived from scaffold and compiled-model output folder names so generated C# remains valid.
Changes:
- Normalize output-directory namespace segments through
ICSharpHelper.Namespace. - Add regression coverage for spaces, punctuation, numeric names, nested paths, and separate context directories.
- Preserve explicit namespaces and existing migration behavior.
| File | Reviewed changes |
|---|---|
test/EFCore.Design.Tests/Design/Internal/DbContextOperationsTest.cs |
Adds coverage for valid namespaces in optimized compiled-model output. |
test/EFCore.Design.Tests/Design/Internal/DatabaseOperationsTest.cs |
Adds scaffolding namespace regression coverage, but does not verify the sanitized namespace in generated entity files. |
src/EFCore.Design/Design/Internal/DbContextOperations.cs |
Sanitizes namespaces derived from compiled-model output directories. |
src/EFCore.Design/Design/Internal/DatabaseOperations.cs |
Sanitizes namespaces derived from reverse-engineering output directories. |
Review effort: Lite
AndriySvyryd
approved these changes
Oct 22, 2026
Member
|
Thanks for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24607
Scaffold and dbcontext optimize used the output folder names as is when building the namespace. So a folder like "Example Folder" or "My-Models" gave a namespace that doesnt compile. For optimize only the using in the assembly attributes file was broken, the namespace itself was already cleaned there.
Now the folder names go through the same helper migrations use, so you get ConsoleApp.ExampleFolder like discussed in the issue. Migrations are not changed.
Added tests in DatabaseOperationsTest and DbContextOperationsTest. I ran the new tests locally but not the whole suite, so lets see what CI says.