dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

[Blazor] Changing a parameter with default value to nullable causes it's name not to be unique when using hot reload #50579

Open agnostk opened 1 year ago

agnostk commented 1 year ago

Is there an existing issue for this?

Describe the bug

When using Blazor, changing a parameter with a default value to nullable leads to a InvalidOperationException error while using hot reload.

Workaround:

Expected Behavior

The code should compile and run without any issues.

Steps To Reproduce

  1. Start a new blazorserver project:
dotnet new blazorserver -o BlazorApp --no-https
  1. Run it with hot reload:
dotnet watch
  1. Change the @code block of Pages/Counter.razor to the following:
[Parameter]
public int IncrementAmount { get; set; } = 1;

private int currentCount = 0;

private void IncrementCount()
{
    currentCount += IncrementAmount;
}
  1. Save the file to trigger hot reload.

  2. Change the parameter initialization to a nullable integer and adapt its method:

[Parameter]
public int? IncrementAmount { get; set; }

private void IncrementCount()
{
    currentCount += IncrementAmount ?? 1;
}
  1. Save the file to trigger hot reload.

  2. Navigate to your project URL and go to the /counter page.

Exceptions (if any)

The type 'BlazorApp.Pages.Counter' declares more than one parameter matching the name 'incrementamount'. Parameter names are case-insensitive and must be unique.

.NET Version

7.0.306

Anything else?

Additional Information Output of dotnet --info

.NET SDK:
 Version:   7.0.306
 Commit:    f500069cb7

Runtime Environment:
 OS Name:     debian
 OS Version:  11
 OS Platform: Linux
 RID:         debian.11-x64
 Base Path:   /usr/share/dotnet/sdk/7.0.306/

Host:
  Version:      7.0.9
  Architecture: x64
  Commit:       8e9a17b221

.NET SDKs installed:
  7.0.306 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found
mkArtakMSFT commented 1 year ago

@tmat can you please look into this? Thanks!

tmat commented 1 year ago

Blocked on: https://github.com/dotnet/runtime/issues/75154, https://github.com/dotnet/roslyn/issues/

ghost commented 1 year ago

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.

ghost commented 9 months ago

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.