I've been having a play arond trying to get blazor components to work with Umbraco 9.
I'm trying to pass in an umbraco generated model to the blazor component like so
@(await Html.RenderComponentAsync<CounterPartialClass>(RenderMode.ServerPrerendered, new { Model = Model}))
However i get the following error
JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles.
Has anyone achieved this or found a way around it?
As the exception details, you could set your JsonSerializerOptions to support cycles, how you would go about this in Umbraco is beyond me though.
An alternative method would be to map the model to your own models which don't include circular references (which umbraco generated classes contain, eg: parent->child->parent->child etc..)
Another option would be to query your content in the Blazor component (OnInitializedAsync) based on simple type parameters that you pass to your component.
That way no object cycles need to be serialized.
It's hard to provide examples with no code provided, but either of these methods should prevent this issue.
I agree with Pavlos' suggestions! With Blazor it's quite tricky to directly reference Umbraco models, so it would probably be better to use your own models that you pass into your Blazor component so that you don't have unnecessary references!
This also means that your Blazor components will be less dependend on the models that are generated by Umbraco!
Umbraco 9 Blazor Components
I've been having a play arond trying to get blazor components to work with Umbraco 9.
I'm trying to pass in an umbraco generated model to the blazor component like so
However i get the following error
Has anyone achieved this or found a way around it?
Thanks in advance
Hi, how are you? Did you manage to solve it? I am having the same problem.
As the exception details, you could set your JsonSerializerOptions to support cycles, how you would go about this in Umbraco is beyond me though.
An alternative method would be to map the model to your own models which don't include circular references (which umbraco generated classes contain, eg: parent->child->parent->child etc..)
Another option would be to query your content in the Blazor component (OnInitializedAsync) based on simple type parameters that you pass to your component. That way no object cycles need to be serialized.
It's hard to provide examples with no code provided, but either of these methods should prevent this issue.
Hi Liam,
I agree with Pavlos' suggestions! With Blazor it's quite tricky to directly reference Umbraco models, so it would probably be better to use your own models that you pass into your Blazor component so that you don't have unnecessary references!
This also means that your Blazor components will be less dependend on the models that are generated by Umbraco!
Hope this helped!
is working on a reply...