dotnet / dotnet/aspnetcore

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

Open
#54,002 4 comments 5 reactions 0 assignees View on GitHub
area-blazor enhancement Pillar: Dev Experience
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] 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

```

@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](https://github.com/dotnet/aspnetcore/assets/4840590/d71e93df-382b-4231-99c1-5ca4895188db)

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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.