False-Positive csharpsquid:S3459 When using Blazor @ref

Make sure to read this post before raising a thread here:

Then tell us:
When using Blazor @ref to assign the reference of property in a code behind csharpsquid:S3459 is generated.

  • What language is this for? C#/Razor
  • Which rule? csharpsquid:S3459
  • Why do you believe it’s a false-positive/false-negative?

The variable is assigned in the generated razor code.

  • Are you using
    • SonarQube Cloud? Yes
    • SonarQube Server / Community Build - which version?
    • SonarQube for IDE - which IDE/version? Rider 10.27.0.81781
      • in connected mode with SonarQube Server / Community Build or SonarQube Cloud? No
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

MyComponent.razor

<div @ref="RootElement">Some Content</div>

MyComponent.razor.cs

public sealed partial class MyComponent: ComponentBase
{
    private ElementReference RootElement { get; set; }
}
1 Like

Hello @groogiam thanks for reporting this.

Could you please provide us with more complete reproducer?
I cannot call the private property in the razor component. Additionally, this example does not compile for me since the the property needs to be referred via the class.

I’m not a blazor expert so I might be missing something, however a more complete repro would be super useful.

Thanks a lot!

1 Like

See attached repro. Strangely enough it does not seem to be flagged by the analyzer only the in Sonar IDE.

S3459Repro.zip (3.0 KB)

Here is the output in Rider.

Thanks.

@Mary Any update on this? I have noticed that this does not get flagged when I use the analyzer package. It seems to only manifest in the Sonar IDE plugin. Thanks.

@groogiam Hello!
I’ll take a look today and come back to you with an update.
Apologies for the delay, we have limited capacity at the moment.
Thanks for your understanding.

1 Like

Hello @groogiam this is probably related to the IDE extension.
I asked the corresponding team to take a look.
We’ll come back once we have news.
Thanks a lot for the repro - it made the investigation much easier.

1 Like

Hi @groogiam , sorry for the late reply.

We unfortunately do not yet support Razor file analysis in Rider (both .razor and .razor.cs). The issue here is that these files are still being analyzed when they shouldn’t be.

I’ve identified one scenario where this happens: if you open your project with a Razor file already open, it will be analyzed.

For now, the workaround will be to prevent Razor files from being analyzed in such cases. In the long term, we hope to add full support for them in Rider.

Thank you!