Open
Description
openedon Sep 8, 2023
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
- Start a new
blazorserver
project:
dotnet new blazorserver -o BlazorApp --no-https
- Run it with hot reload:
dotnet watch
- Change the
@code
block ofPages/Counter.razor
to the following:
[Parameter]
public int IncrementAmount { get; set; } = 1;
private int currentCount = 0;
private void IncrementCount()
{
currentCount += IncrementAmount;
}
-
Save the file to trigger hot reload.
-
Change the parameter initialization to a nullable integer and adapt its method:
[Parameter]
public int? IncrementAmount { get; set; }
private void IncrementCount()
{
currentCount += IncrementAmount ?? 1;
}
-
Save the file to trigger hot reload.
-
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