Skip to content

Conversation

@martincostello
Copy link
Member

Strip generic type parameter attributes from partial classes emitted by the logging source generator to avoid CS0579 errors from duplicate attributes.

Fixes #97498.

@ghost ghost added area-Extensions-Logging community-contribution Indicates that the PR has been added by a community member labels Jan 28, 2024
@ghost
Copy link

ghost commented Jan 28, 2024

Tagging subscribers to this area: @dotnet/area-extensions-logging
See info in area-owners.md if you want to be subscribed.

Issue Details

Strip generic type parameter attributes from partial classes emitted by the logging source generator to avoid CS0579 errors from duplicate attributes.

Fixes #97498.

Author: martincostello
Assignees: -
Labels:

area-Extensions-Logging

Milestone: -

@tarekgh
Copy link
Member

tarekgh commented Jan 29, 2024

@martincostello The original issue reported in #97498 was about The type or namespace name 'DynamicallyAccessedMembersAttribute' could not be found (are you missing a using directive or an assembly reference?). But you are saying Strip generic type parameter attributes from partial classes emitted by the logging source generator to avoid CS0579 errors from duplicate attributes. .

I expect to fix this by fully qualifying the attribute in the emitted source. What exactly causes CS0579 errors from duplicate attributes?

@tarekgh
Copy link
Member

tarekgh commented Jan 29, 2024

CC @eerhardt if you have any input for this.

@martincostello
Copy link
Member Author

What exactly causes CS0579 errors from duplicate attributes?

Having the attributes defined in both partial classes, it just flat-out doesn't compile. Adding the usings/fully-qualifying just causes a new CS0579 error.

#97498 (comment)

As far as I can tell, only one partial class can annotate the type parameters, so the generator shouldn't emit them and leave it up to the user's code to do so. That's what this PR does.

@tarekgh
Copy link
Member

tarekgh commented Jan 29, 2024

CC @geeknoid and @joperezr as FYI.

@tarekgh
Copy link
Member

tarekgh commented Jan 29, 2024

@martincostello I see what you are saying now. Thanks for clarification.

Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @martincostello for your help providing the fix!

@martincostello
Copy link
Member Author

@tarekgh No problem!

Is this change something that could be considered for backporting to 8.0 after merge?

We have a base library targeting net8.0 we use internally for building serverless apps that makes heavy use of generics and the logging source generator. I found this issue while working on adding AoT support to it.

This issue blocks us from adopting native AoT there without significant refactoring of all the logging in that library, which in turn blocks all the apps built on top of it.

@tarekgh
Copy link
Member

tarekgh commented Jan 30, 2024

Is this change something that could be considered for backporting to 8.0 after merge?

I can check if this is meeting the servicing bar. Let's get this first in the main and then we can follow-up to see if we can port it to servicing.

CC @ericstj

Strip generic type parameter attributes from partial classes emitted by the logging source generated to avoid CS0579 errors from duplicate attributes.
Fixes dotnet#97498.
Update comment as suggested by code review.
Verify that attributes on generic type parameters are not lost.
@tarekgh
Copy link
Member

tarekgh commented Jan 30, 2024

/backport to release/8.0-staging

@github-actions
Copy link
Contributor

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/7716311245

@tarekgh
Copy link
Member

tarekgh commented Jan 31, 2024

@martincostello this is now ported to servicing branch. Will be released around March.

@martincostello
Copy link
Member Author

@tarekgh Thanks! ❤️

@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Extensions-Logging community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logging source generator fails to compile if class has [DynamicallyAccessedMembers]

3 participants