- What language is this for? C#, .net Framework 4.7 AND .net 8
- Which rule? S2325
- Why do you believe it’s a false-positive/false-negative? Solving this warning causes the error CS0176 to appear
- Are you using
- SonarQube for IDE - which IDE/version? Visual Studio, 8.8.0.11278
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
The following WPF window :
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button Content="Push me!" HorizontalAlignment="Left" Margin="431,217,0,0" VerticalAlignment="Top" Click="Button_Click"/>
</Grid>
</Window>
And the code-behind:
using System.Windows;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("H");
}
}
}
Causes S2325 to appear for Button_Click. Solving it (making the method static) triggers the compiler error CS0176, claims that the method in inaccessible with an instance reference.
Therefore, solving the following SonarQube warning is impossible. There should be an exception for WPF event methods.
Thank you in advance for fixing this issue!