There is an issue with csharpsquid:S1144 (unused code detection) with razor pages

The rule which detects unused code (csharpsquid:S1144) does not work for razor pages/code behind files. Any method/member which is actually referenced in the razor page for event is flagged in sonar lint. I’m not sure this is a problem outside of sonar lint because I don’t see it listed as an issue once the code has been uploaded to sonarcloud.

Unfortunately, I have to remove this rule for now so that it doesn’t cause developers so much grief/paranoia when writing code.

edit: The same applies to rule csharpsquid:S4487

Is it at least possible for me to exclude these rules on any files matching this wildcard pattern: *.razor* ?

HI @SD321. Just to check - are you using Rider?

@duncanp Yes I am

@duncanp Hi, did that help you find the issue?

Hi @SD321

Sorry for the very late reply, for some reason this thread was missed by our team.

I struggle to reproduce because when I create a Razor page in Rider, it is using MVC pattern (so the page can only access public methods of the model).

For reference, here is a reproducer:


@page "/event"


        New title
        <input @bind="newHeading" />
    <button @onclick="UpdateHeading">
        Update heading

        <input type="checkbox" @onchange="CheckChanged" />


namespace RazorPagesMovie.Pages;

public partial class Event
    private string currentHeading = "Initial heading";
    private string? newHeading;
    private string checkedMessage = "Not changed yet";

    private void UpdateHeading()
        currentHeading = $"{newHeading}!!!";

    private void CheckChanged()
        checkedMessage = $"Last changed at {DateTime.Now}";

Yes, you can configure complex rule exclusion patterns in SonarCloud, and it will be picked up by SonarLint.

I will also see if there is something we can do to better handle this case in our analyzer.

Thanks for the update.
Can you try it with a blazor server app? Not sure if that makes a difference. I believe I did something to ignore this rule alrogether, temporarily, so I’ll enable it again and look to see if it’s still happening if you still don’t see any issues in the latest version of Rider.

1 Like

Sorry if I was not clear: I did manage to reproduce :slight_smile: Just it took me some time.

1 Like


Thanks for sharing this. We are currently exploring including the C# in .cshtml and .razor files in our analysis and I hope that this will resolve this issue. As you can imagine this is quite a big step and we are in the early stages but initial signs look promising. I’ll try and update this post as things progress.

.NET Ecosystem Product Manager