Skip to content

ParameterView unchecked type casts when splatting provides unhelpful error messages #67285

Description

@sconosciute

Summary

When setting component parameters directly compile time analysis will find mismatched types and provide a helpful error message pointing to the exact position of the problem with the type cast failing. If instead a developer splats attributes onto the component then a mismatched type will only be caught at runtime during ParameterView.HasParameterChanged() which results in an unhelpful error message stating that types could not be converted (e.g. could not convert from Int32 to Double) but does not provide the name of the parameter or calling component.

Motivation and goals

Vague error messages at runtime are confusing and upsetting to the best developers, adding a type check and providing some more specific information will aid in tracking down specific attributes causing issues without having to comb through every component and splat in use on a page.

In scope

Developer splats attributes onto a component, the type of an attribute does not match: the developer should receive a specific runtime error which provides the name of the parameter and calling component with the mismatch.

Out of scope

Static analysis for attribute splat type checking. While that would be a boon, I think it is best to focus on helpful error messaging first and preventative measures later.

Risks / unknowns

If an exception other than InvalidCastException is thrown from within ParameterView this could cause issues for developers who are catching the specific exception, but I find it an unlikely scenario given the type of issue.

Examples

I ran into this today using a MudTextField component from MudBlazor

var debounceSplat = new Dictionary<string, object>{ {"DebounceInterval", 500} };
//This splat uses the wrong type, DebounceInterval expects an int32.

<MudTextField DebounceInterval="500" /> //Works, implicit cast from int to double
<MudTextField DebounceInterval="@("bob") /> //Results in expected compile time error message
<MudTextField @attributes="debounceSplat" /> //Results in vague exception produced from ParameterView

Using the debounceSplat as above should result in an error that looks like

Unhandled exception rendering component: Unable to cast object of type 'System.Int32' to type 'System.Double'.
      System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.Double'.
         at Microsoft.AspNetCore.Components.ParameterView.TryGetValue[TValue](String parameterName, TValue& result)
         at MudBlazor.ParameterViewExtensions.HasParameterChanged[T](ParameterView parameters, String parameterName, T parameterValue, T& value, IEqualityComparer`1 comparer)
         at MudBlazor.State.ParameterStateInternal`1.HasParameterChanged(ParameterView parameters)
         at MudBlazor.State.ParameterContainer.CollectChangedHandlers(ParameterView parameters)
         at MudBlazor.State.ParameterContainer.SetParametersWithHandlersAsync(Func`2 baseSetParametersAsync, ParameterView parameters)
         at MudBlazor.MudBaseInput`1.SetParametersAsync(ParameterView parameters)

Even just including the name of the parameter in the error message would go a long way towards helping developers solve this problem in the wild.

Activity

  1. added
    design-proposalThis issue represents a design proposal for a different issue, linked in the description
    on Jun 17, 2026
  2. added
    help wantedUp for grabs. We would accept a PR to help resolve this issue
    on Jun 18, 2026
  3. added this to the Backlog milestone on Jun 18, 2026
  4. dx3mirror commented on Jun 29, 2026

    @dx3mirror

    I'd like to work on this. Planning to improve the error message in ParameterView.TryGetValue to include the parameter name and source/target types.

  5. kotlarmilos commented on Nov 20, 2026

    @kotlarmilos
    Member

    Thanks for the suggestion. The default parameter-setting path already reports the parameter name, and TryGetValue is called by user code that knows which parameter it requested. The diagnostic improvement does not seem necessary for the framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Componentscopilot-candidatedesign-proposalThis issue represents a design proposal for a different issue, linked in the descriptionhelp wantedUp for grabs. We would accept a PR to help resolve this issue

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions