Skip to content

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

Open

Description

Is there an existing issue for this?

  • I have searched the existing issues

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:

  • Restart the application manually.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Pillar: Dev ExperiencePriority:0Work that we can't release withoutarea-blazorIncludes: Blazor, Razor ComponentsblockedThe work on this issue is blocked due to some dependencyfeature-hot-reloadThis issue is related to the Hot Reload feaature

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions