Open sbwalker opened 12 months ago
Thanks for contacting us.
We're moving this issue to the .NET 9 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Thanks for contacting us.
We're moving this issue to the .NET 9 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Is there an existing issue for this?
Describe the bug
When using the standard DynamicComponent (introduced in .NET 6) and specifying an instance-based @rendermode attribute ie.
The component throws a run-time error related to serialization:
DynamicComponent expects a Type parameter which is of type System.RuntimeType - however in .NET 8 parameters must be serializable.
Expected Behavior
DynamicComponent is widely used in Blazor applications to construct razor components dynamically based on type information. I would expect DynamicComponent to render a component in exactly the same manner as it does in .NET 6 and .NET 7.
Steps To Reproduce
Please see repo: https://github.com/oqtane/OqtaneSSR which is based on the standard Blazor Web template in .NET 8 RC2. Set the appsettings.json Modules property to:
When you run the application, it will immediately throw a run-time error. This is caused by the line:
<DynamicComponent Type="@_type" @rendermode="RenderMode.InteractiveServer">
in OqtaneSSR\Components\Router\ModuleInstance2.razor
Exceptions (if any)
An unhandled exception occurred while processing the request. NotSupportedException: Serialization and deserialization of 'System.RuntimeType' instances is not supported. System.Text.Json.Serialization.Converters.UnsupportedTypeConverter.Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
.NET Version
8.0.0-rc.2.23480.2
Anything else?
A workaround to this problem is to create a custom component which accepts a TypeName (rather than a Type) and use RenderFragment to render it:
Note that this workaround does not support Parameters - which is another problem with DynamicComponent as it uses a Dictionary for parameters.