-
Notifications
You must be signed in to change notification settings - Fork 81
Added new kb article common-kb-stackoverflowexception-editing-circular-references #2328
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
Merged
ntacheva
merged 9 commits into
master
from
new-kb-common-kb-stackoverflowexception-editing-circular-references-d47ad37d992b4a5488a47fc51bb714f7
Sep 17, 2024
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
add051c
Added new kb article common-kb-stackoverflowexception-editing-circula…
e9c2850
Update knowledge-base/common-kb-stackoverflowexception-editing-circul…
ntacheva 53a8d9b
Update knowledge-base/common-kb-stackoverflowexception-editing-circul…
ntacheva 9f90e44
Update knowledge-base/common-kb-stackoverflowexception-editing-circul…
ntacheva 51b77c4
Update knowledge-base/common-kb-stackoverflowexception-editing-circul…
ntacheva cb12be7
Update knowledge-base/common-kb-stackoverflowexception-editing-circul…
ntacheva 7d78237
chore(common): address feedback
ntacheva 595a6ad
Update knowledge-base/common-stackoverflowexception-editing-circular-…
ntacheva 0f82696
chore(common): link foreign key column kb
ntacheva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
knowledge-base/common-stackoverflowexception-editing-circular-references.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| --- | ||
| title: StackOverflowException When Editing Items with Circular References in Grid for Blazor | ||
| description: This article describes how to avoid a StackOverflowException by modifying object properties to prevent circular references when editing items in the Grid, ListView or TreeList for Blazor. | ||
| type: troubleshooting | ||
| page_title: Editing Items with Circular References in Grid for Blazor Throws StackOverflowException | ||
| slug: common-kb-stackoverflowexception-editing-circular-references | ||
| tags: telerik, blazor, grid, gantt, listview, scheduler, treelist, stackoverflowexception, circular reference, editing | ||
| res_type: kb | ||
| ticketid: 1660663, 1592634 | ||
| --- | ||
|
|
||
| ## Environment | ||
|
|
||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td>Product</td> | ||
| <td>Grid for Blazor, <br />Gantt for Blazor, <br/>ListView for Blazor, <br />Scheduler for Blazor<br />TreeList for Blazor</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| ## Description | ||
|
|
||
| I get a `StackOverflowException` when attempting to edit an item in the Grid for Blazor. The issue occurs when I have circular references in the data items. | ||
|
|
||
| ## Cause | ||
|
|
||
| The data-bound components that allow editing (for example Grid, ListView, TreeList, and more) create a copy of the original object when the user initiates editing. | ||
|
|
||
| The Telerik UI for Blazor internal object cloning algorithm uses reflection to loop through the object properties and copy them in the cloned object. When the model contains a self-reference object property, the cloning logic loops again and again resulting in an infinite reflection loop and this causes the `StackOverflowException` exception. | ||
|
|
||
| ## Solution | ||
|
|
||
| To resolve the `StackOverflowException`, modify the data model to eliminate circular references. Replace object properties that reference other objects within the same model with primitive properties that store unique identifiers. This change prevents the infinite loop during the cloning process. | ||
|
|
||
| For example, instead of having a class with a property that references another object: | ||
|
|
||
| ```csharp | ||
| public class Employee | ||
| { | ||
| public int Id { get; set; } | ||
| public Employee Manager { get; set; } | ||
| } | ||
| ``` | ||
|
|
||
| Modify the class to include a primitive property that holds a unique identifier: | ||
ntacheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```csharp | ||
| public class Employee | ||
| { | ||
| public int Id { get; set; } | ||
| public int ManagerId { get; set; } | ||
| } | ||
| ``` | ||
|
|
||
| ## See Also | ||
|
|
||
| * [Grid Editing]({%slug components/grid/editing/overview%}) | ||
| * [Gantt Editing]({%slug gantt-tree-editing%}) | ||
| * [ListView Editing]({%slug listview-editing%}) | ||
| * [Scheduler Editing]({%slug scheduler-appointments-edit%}) | ||
| * [TreeList Editing]({%slug treelist-editing-overview%}) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.