S6797 — Blazor query parameter type should be supported

Language
C#
Type
Bug
Severity
Major
Tags
blazor

Why is this an issue?

The SupplyParameterFromQuery attribute can be used to specify that a component parameter, of a routable component, comes from the query string.

Component parameters supplied from the query string support the following types:

Query parameters should have one of the supported types. Otherwise, an unhandled exception will be raised at runtime.


Unhandled exception rendering component: Querystring values cannot be parsed as type '<type>'.
System.NotSupportedException: Querystring values cannot be parsed as type '<type>'
...

How to fix it

Change the parameter type to one of the following ones:

Code examples

Noncompliant code example


@page "/print"
<p> Parameter value is: @Value </p>
@code {
    [Parameter]
    [SupplyParameterFromQuery()]
    public TimeSpan Value { get; set; }     // Noncompliant
}

Compliant solution


@page "/print"
<p> Parameter value is: @Value </p>
@code {
    [Parameter]
    [SupplyParameterFromQuery()]
    public long Value { get; set; }         // Compliant
}

Resources

Documentation

↑ Back to top