Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
sbwalker opened this issue Feb 13, 2024 · 2 comments
Open
1 task done
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one Pillar: Dev Experience
Milestone

Comments

@sbwalker
Copy link

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Feb 13, 2024
@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. Pillar: Dev Experience enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed bug This issue describes a behavior which is not expected - a bug. labels Feb 14, 2024
@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 10 Planning, Backlog Feb 14, 2024
@clarity99
Copy link

This! It took me most of the day to figure out that serialization is the issue, when my component wasn't working when I set the parameter to IQueryable data source.

@T-mp
Copy link

T-mp commented May 13, 2024

Is there currently a known way to determine the affected class/parameter?
Debugging is not possible because the error only occurs on the server, not when I start it from Visual Studio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one Pillar: Dev Experience
Projects
None yet
Development

No branches or pull requests

4 participants