Route parameters with non-string values fails
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
In .NET 8 preview 5, when creating a SSR Blazor app and using route parameters with e.g. int type, the page fails to load with an error: InvalidCastException: Unable to cast object of type ‘System.String’ to type ‘System.Int32’.
Here is the component I used to test this:
@page "/counter/{currentCount:int?}"
<p role="status">Current count: @CurrentCount</p>
@code {
[Parameter] public int CurrentCount { get; set; }
}
I tried this on .NET 7 Blazor WASM app and it worked.
Expected Behavior
When going to an url https://localhost:7208/counter/5 the CurrentCount property should be set to 5.
Steps To Reproduce
Create a .NET 8 Blazor SSR app, copy the code to a Counter.razor component and navigate to it’s url.
.NET Version
8.0.100-preview.5.23303.2
Issue Analytics
- State:
- Created 3 months ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Route parameters with non-string values fails
Route parameters with non-string values fails · Summary · Jobs. backport. cleanup · run_backport · Run details. Usage · Workflow file.
Read more >Passing strings as route parameters in Angular without ...
Edit: The variable params is of type URLSearchParams() . This is how I'm trying to extract the parameter: this.route.paramMap.switchMap( ...
Read more >How to Use @Input() to Read Angular Route Parameters
We add an input property using the @Input() decorator. @Input() id = '';. We can name the input property the same as the...
Read more >MySQL Cookbook - Page 917 - Google Books Result
PATH environment variable error when invoking mysql, 4 solution, ... 879 nonstring values, 308 regular expressions (see regular expres‐sions) SQL patterns, ...
Read more >sys — System-specific parameters and functions
This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Markz878 thanks for contacting us.
Yes, this seems to be a bug (more of an integration issue).
@surayya-MS @SteveSandersonMS this is very likely a difference between asp.net core routing and Blazor routing.
Blazor will use the constraints to cast the value to the proper type, while ASP.NET Core won’t do so.
I suggest two possible action plans:
Router
to convert the string to the appropriate type.RouteView
to do this casting instead (since it knows the parameter types).We’ve discussed this offline and decided to go with the following approach. As a short-term mitigation we will make so that the client router will ignore the server router logic completely for now.
In parallel, we will see if we can bring the missing features to the routing system, so that this scenario works properly. If we manage to do that before rc2 and we are happy with the approach, we will take that and remove the temporary fix. Otherwise, we will come up with the proper fix in .NET 9, leaving the simple workaround in place in .NET 8.
//cc @SteveSandersonMS , @javiercn, @surayya-MS