Open desmondinho opened 1 week ago
@desmondinho thanks for contacting us.
Under the hood these parameters are serialized using System.Text.Json
, so what's likely going on is that the serializer is not able to select a constructor in the second case. Not sure what the reason is for the 3rd one working vs the second.
You can use [JsonConstructor]
to disambiguate or make other constructors internal/private and make a single one public.
If you want to further test this out, simply create a console app, serialize the types, and then try deserializing the different combinations.
Hi @desmondinho. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Is there an existing issue for this?
Describe the bug
I am passing a model(s) as a parameter to an interactive component that is rendered on a SSR page and I experience different unexpected behaviors such as exceptions or parameter value reset. Read below for a better understanding.
The Component:
The model(s):
The usage on the page:
Ok: a model with the primary constructor; works as expected
NotOk: a model with 2 explicit constructors; throws an exception (see the Exceptions field below)
AnotherNotOk: a model with 3 explicit constructors, a fix for the
NotOk
; a default constructor was added because it fixes the exception thrown with theNotOk
; initially, the propertyValue
is correctly shown, however it gets reset after a bit (prerendering stuff?)Maybe 2 and 3 should be reported separately but I thought that they might be somehow related.
Expected Behavior
NotOk should not throw the exception. Why explicitly defined default contstuctor fixes the issue? Shouldn't it work without it since these are auto-generated under the hood anyway?
AnotherNotOk, as I said, "fixes" the
NotOk
but the propertyValue
gets reset which does not seem ok.Steps To Reproduce
Minimal reproduction project
Ok behavior:
Not Ok behavior:
Home.razor
Another Not Ok behavior:
Home.razor
Value
property dissappearsP.S. The exception message does not look good. https://github.com/dotnet/aspnetcore/issues/51749#issuecomment-1831675663
Exceptions (if any)
Error: One or more errors occurred. (Could not parse the parameter value for parameter '{definition.Name}' of type '{definition.TypeName}' and assembly '{definition.Assembly}'.)
.NET Version
8.0.304
Anything else?
Please tell me if you need more info.
Thanks!