-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging Source Generator fails to compile due to CS8795 error with file-scoped namespaces #57880
Comments
Tagging subscribers to this area: @maryamariyan Issue DetailsDescriptionIf a class used to provide the partial methods for the Logging Source Generator uses file-scoped namespaces, the project fails to compile with errors similar to the below.
Minimal repro
|
Author: | martincostello |
---|---|
Assignees: | - |
Labels: |
|
Milestone: | - |
Potential fix in // determine the namespace the class is declared in, if any
SyntaxNode? potentialNamespaceParent = classDec.Parent;
- while (potentialNamespaceParent != null && potentialNamespaceParent is not NamespaceDeclarationSyntax)
+ while (potentialNamespaceParent != null &&
+ potentialNamespaceParent is not NamespaceDeclarationSyntax &&
+ potentialNamespaceParent is not FileScopedNamespaceDeclarationSyntax)
{
potentialNamespaceParent = potentialNamespaceParent.Parent;
}
- if (potentialNamespaceParent is NamespaceDeclarationSyntax namespaceParent)
+ if (potentialNamespaceParent is BaseNamespaceDeclarationSyntax namespaceParent)
{ The type |
Seems like we should fix this for 6.0.0 |
Handle namespace not being emitted when file-scoped namespaces are used for a log class. Relates to dotnet#57880.
I've opened a PR with the proposed fix #57880 (comment) in #57894. |
Handle namespace not being emitted when file-scoped namespaces are used for a log class. Relates to #57880.
We merged the fix to main, will need to backport to 6.0.0 and test/fix for JSON if needed too. /cc @layomia |
JSON seems fine: #57894 (comment) |
Handle namespace not being emitted when file-scoped namespaces are used for a log class. Relates to dotnet#57880.
…spaces (#57894) (#59100) * Handle file-scoped namespaces (#57894) Handle namespace not being emitted when file-scoped namespaces are used for a log class. Relates to #57880. * Fix build issue Co-authored-by: Martin Costello <[email protected]>
Has been fixed by #57894 |
Description
If a class used to provide the partial methods for the Logging Source Generator uses file-scoped namespaces, the project fails to compile with errors similar to the below.
Minimal repro
Project.csproj
Program.cs
Logger.cs
Expected Output
Configuration
.NET SDK
6.0.100-rc.1.21420.39
Microsoft.Extensions.Logging
6.0.0-rc.1.21420.7
Regression?
No.
The text was updated successfully, but these errors were encountered: