Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 25, 2025

Fixes #45793

The BL0007 diagnostic ("Component parameters should be auto properties") previously provided minimal context about why this rule exists and what developers should do instead. This led to confusion since the warning appears even when properties have custom logic, which typically wouldn't trigger auto-property suggestions in other contexts.

Changes Made

Enhanced diagnostic message: Updated from the generic "Component parameter '{0}' should be auto property" to "Component parameter '{0}' should be auto property. Manipulating component parameters can result in infinite loops and unintended side effects."

Added comprehensive description: The diagnostic now includes a detailed description explaining:

  • Why component parameters should be auto properties
  • The specific risks of manipulating component parameters (infinite loops and unintended side effects)
  • Alternative approaches developers should use: @bind:after or @bind:set for parameter manipulation

Example of the improved diagnostic experience:

Before:

warning BL0007: Component parameter 'MyComponent.Value' should be auto property

After:

warning BL0007: Component parameter 'MyComponent.Value' should be auto property. Manipulating component parameters can result in infinite loops and unintended side effects.

Description: Component parameters should be auto properties. Manipulating component parameters can result in infinite loops and unintended side effects. Use @bind:after or @bind:set instead to adjust values or trigger additional callbacks.

This addresses the core issue where developers had to search online to understand why this diagnostic appeared and what the recommended patterns are. The enhanced message provides immediate context and actionable guidance.

Testing

  • All existing analyzer tests continue to pass
  • Updated test expectations to match the new improved diagnostic messages
  • Verified the diagnostic description is properly displayed through the analyzer infrastructure
Original prompt

This section details on the original issue you should resolve

<issue_title>Update BL0007 warning to explain why a parameter should be an auto-property and what to do</issue_title>
<issue_description>### Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Also raised:

I got this warning here:
image

I was confused because the hint that something can be made an auto property usually only happens if there is no logic in the get/set. That isn't the case here, and it turns out that is by design.

The comment here by @SteveSandersonMS explains why this rule exists and what the right pattern is for apps that want logic to run on parameter change. However, the message given to the developer doesn't have any of this useful information. The code analysis text needs to be more descriptive and have a link to documentation that shows the right pattern.

The code analysis warning shouldn't require googling to figure out why it happened and how to fix it.

There are lots of comments and upvotes of developers running into this warning here.

Expected Behavior

More detail. A link to documentation with the right pattern.

Steps To Reproduce

[Parameter, EditorRequired]
public required List<DimensionScope> MatchedDimensions
{
    get => _matchedDimensions;
    set
    {
        if (_matchedDimensions != value)
        {
            _matchedDimensions = value;
            _dimensionsOrDurationChanged = true;
        }
    }
}

Exceptions (if any)

No response

.NET Version

.NET 8

Anything else?

No response</issue_description>

<agent_instructions>We need to update the error message to include the following information "Manipulating component parameters can result in infinite loops and unintended side effects. Use @bind:after or @bind:set instead to adjust values or trigger additional callbacks instead."</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@ We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our [Triage Process](https://github.com/dotnet/aspnetcore/blob/main/docs/TriageProcess.md). @ Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.</comment_new>

---- **Additional instructions:**

We need to update the error message to include the following information "Manipulating component parameters can result in infinite loops and unintended side effects. Use @bind:after or @bind:set instead to adjust values or trigger additional callbacks instead."

Fixes #51372


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor

Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

@Copilot Copilot AI changed the title [WIP] Update BL0007 warning to explain why a parameter should be an auto-property and what to do Update BL0007 diagnostic to provide clearer guidance on component parameter patterns Sep 25, 2025
@Copilot Copilot AI requested a review from javiercn September 25, 2025 09:59
Copilot finished work on behalf of javiercn September 25, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants