Skip to content
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

Fix S2325 FP: XAML (WPF) event handlers cannot not be static #9695

Closed
PetrJasek89 opened this issue Nov 18, 2024 · 3 comments
Closed

Fix S2325 FP: XAML (WPF) event handlers cannot not be static #9695

PetrJasek89 opened this issue Nov 18, 2024 · 3 comments
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.

Comments

@PetrJasek89
Copy link

Description

XAML event handlers cannot be static. Currently S2325 is raised on XAML event handlers.

The issue is the same as #5536, only instead of WinForms it applies to XAML.

Repro steps

private void SomeControl_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    // Handling of the event
}

Expected behavior

No issue raised as XAML cannot handle static event handlers.

Actual behavior

S2325 is raised.

Known workarounds

Suppression attribute added to all affected methods.

@PetrJasek89
Copy link
Author

I cannot build and test on my system so I didn't want to create a PR with a fix. I have at least created a path (9695.patch) that should fix the issue. It basically copies the fix that was done for #5536.

I think there could be done a small improvement that would also apply to the WinForms case. In both cases, the containing type will be (has to be) partial. Therefore check for this could be added as well.

@sebastien-marichal
Copy link
Contributor

Hello @PetrJasek89,

Thank you for reporting this issue.

I confirm this indeed a false positive.
I will add it to our backlog to tackle it later.

Thank you also for you suggested patch, it seems close to what we would need to do to add this exclusion.

Note for the implementation: Exception list on RSPEC need to updated for this rule.

@sebastien-marichal sebastien-marichal added Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Nov 19, 2024
@sebastien-marichal
Copy link
Contributor

sebastien-marichal commented Nov 20, 2024

I am closing the issue as it has been moved to our internal backlog for future fix: NET-710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants