Skip to content

.NET 8 Blazor - Provide Better Developer Feedback for Parameter Deserialization Issues #54002

@sbwalker

Description

@sbwalker

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

If you are transitioning from Static rendering to Interactive rendering and you are passing parameters from one component to another, it is critical that the parameters are serializable. If a parameter is not serializable you will get a cryptic run-time error in the browser console which does not provide any indication of the root cause:

DeserializationRepro.razor

<InteractiveComponentWithParameter MissingConstructor="@_missingConstructor" @rendermode="InteractiveServer" />

@code {
    private MissingConstructor _missingConstructor = new MissingConstructor("https://www.microsoft.com/");
}

InteractiveComponentWithParameter.razor

@code {
    [Parameter]
    public MissingConstructor MissingConstructor { get; set; }
}

MissingConstructor.cs

    public class MissingConstructor
    {
        //public MissingConstructor() { }

        public MissingConstructor(string url)
        {
            Uri uri = new Uri(url);
            Host = uri.Host;
        }

        public string Host { get; set; }
    }

Running this code will result in a browser console error:

"Error: The list of component operations is not valid."

image

Note that to resolve this issue you simply need to uncomment the parameterless constructor in the MissingConstructor.cs class

    public class MissingConstructor
    {
        public MissingConstructor() { }

        public MissingConstructor(string url)
        {
            Uri uri = new Uri(url);
            Host = uri.Host;
        }

        public string Host { get; set; }
    }

Expected Behavior

Provide an error message which is meaningful and helps a developer identify the source of the problem:

ie. "An error occurred deserializing a component parameter"

Even better would be any reference to the actual component name or parameter name causing the issue.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillar: Dev Experiencearea-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing one

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions