From 7fc00c9f239bf11b8de93c8e9c212871f414cd17 Mon Sep 17 00:00:00 2001 From: NansiYancheva Date: Tue, 29 Oct 2024 18:51:17 +0200 Subject: [PATCH 1/3] docs(common): Add KB for null exception --- knowledge-base/common-struct-error.md | 100 ++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 knowledge-base/common-struct-error.md diff --git a/knowledge-base/common-struct-error.md b/knowledge-base/common-struct-error.md new file mode 100644 index 0000000000..79ddab1891 --- /dev/null +++ b/knowledge-base/common-struct-error.md @@ -0,0 +1,100 @@ +--- +title: Databound Telerik Blazor components do not work and get a null exception +description: Using struct objects for the Data of the component causes error +type: troubleshooting +page_title: Struct data source causes exception +slug: common-kb-struct-error +tags: telerik, blazor, autocomplete, breadcrumb, chart, chiplist, combobox, contextmenu, drawer, dropdownlist, filemanager, gantt, grid, listbox, listview, menu, multicolumncombobox, multiselect, panelbar, pivotgrid, radiogroup, sankey, scheduler, stock chart, treelist, treeview, struct, null exception +ticketid: 1657421 +res_type: kb +--- + +## Environment + + + + + + + +
ProductAutocomplete for Blazor, Breadcrumb for Blazor, Chart for Blazor, ChipList for Blazor, ComboBox for Blazor, ContextMenu for Blazor, Drawer for Blazor, DropDownList for Blazor, FileManager for Blazor, Gantt for Blazor, Grid for Blazor, ListBox for Blazor, ListView for Blazor, Menu for Blazor, MultiColumnComboBox for Blazor, MultiSelect for Blazor, PanelBar for Blazor, PivotGrid for Blazor, RadioGroup for Blazor, Sankey for Blazor, Scheduler for Blazor, Stock Chart for Blazor, TreeList for Blazor, TreeView for Blazor
+ + +## Description +When using a databound component the application gets a null exception and the component does not work. + +## Error Message +When running a Telerik Blazor application the application gets an error similar to the following: +``` +ArgumentNullException: Value cannot be null. (Parameter 'source') +System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) +``` + +## Example to Reproduce +````CSHTML + + + + + + + + + +@code { + private List GridData { get; set; } = new(); + + protected override void OnInitialized() + { + GridData = new List(); + + var rnd = new Random(); + + for (int i = 1; i <= 30; i++) + { + GridData.Add(new Product + { + Id = i, + Name = "Product name " + i, + Price = (decimal)(rnd.Next(1, 50) * 3.14), + Released = DateTime.Now.AddDays(-rnd.Next(1, 365)).AddYears(-rnd.Next(1, 10)).Date, + Discontinued = i % 5 == 0 + }); + + } + + base.OnInitialized(); + } + + public struct Product + { + public int Id { get; set; } + public string Name { get; set; } + public decimal Price { get; set; } + public DateTime Released { get; set; } + public bool Discontinued { get; set; } + } +} +```` + +## Possible Cause +The reason for this error is because the component is databound to a `struct`. + +## Solution +The solution is to use a `class` model, not a `struct`, as documented in the red note [here]({%slug common-features-data-binding-overview%}#how-to-provide-data): + +
+ +````CS + public class Product + { + public int Id { get; set; } + public string Name { get; set; } + public decimal Price { get; set; } + public DateTime Released { get; set; } + public bool Discontinued { get; set; } + } +```` + +## See Also +- [Data Binding Overview]({%slug common-features-data-binding-overview%}) \ No newline at end of file From 8ea3ab0bfef96afc5b1371a9144165cad6b0a001 Mon Sep 17 00:00:00 2001 From: NansiYancheva <106161782+NansiYancheva@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:03:20 +0200 Subject: [PATCH 2/3] Update knowledge-base/common-struct-error.md Co-authored-by: Yordan <60105689+yordan-mitev@users.noreply.github.com> --- knowledge-base/common-struct-error.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/knowledge-base/common-struct-error.md b/knowledge-base/common-struct-error.md index 79ddab1891..e596abb93b 100644 --- a/knowledge-base/common-struct-error.md +++ b/knowledge-base/common-struct-error.md @@ -21,7 +21,8 @@ res_type: kb ## Description -When using a databound component the application gets a null exception and the component does not work. + +When using a data-bound component, the application gets a null exception, and the component does not work. ## Error Message When running a Telerik Blazor application the application gets an error similar to the following: From db308d736000a820f87a4fa03a8419dc634c012d Mon Sep 17 00:00:00 2001 From: NansiYancheva Date: Wed, 30 Oct 2024 19:06:38 +0200 Subject: [PATCH 3/3] docs(common): update after review --- knowledge-base/common-struct-error.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/knowledge-base/common-struct-error.md b/knowledge-base/common-struct-error.md index e596abb93b..0ea258c662 100644 --- a/knowledge-base/common-struct-error.md +++ b/knowledge-base/common-struct-error.md @@ -1,8 +1,8 @@ --- -title: Databound Telerik Blazor components do not work and get a null exception +title: Databound Telerik Blazor Components Do Not Work and Get a Null Exception description: Using struct objects for the Data of the component causes error type: troubleshooting -page_title: Struct data source causes exception +page_title: Struct Data Source Causes Exception slug: common-kb-struct-error tags: telerik, blazor, autocomplete, breadcrumb, chart, chiplist, combobox, contextmenu, drawer, dropdownlist, filemanager, gantt, grid, listbox, listview, menu, multicolumncombobox, multiselect, panelbar, pivotgrid, radiogroup, sankey, scheduler, stock chart, treelist, treeview, struct, null exception ticketid: 1657421 @@ -22,16 +22,13 @@ res_type: kb ## Description -When using a data-bound component, the application gets a null exception, and the component does not work. - -## Error Message -When running a Telerik Blazor application the application gets an error similar to the following: +When using a data-bound component, the application gets a null exception, and the component does not work. When running the Telerik Blazor application the application gets an error similar to the following: ``` ArgumentNullException: Value cannot be null. (Parameter 'source') System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) ``` -## Example to Reproduce +To reproduce the problem, you can use the following code sample: ````CSHTML @@ -78,11 +75,11 @@ System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) } ```` -## Possible Cause -The reason for this error is because the component is databound to a `struct`. +## Cause +The cause for this null exception is the binding of Telerik UI for Blazor components to a `struct` component model. ## Solution -The solution is to use a `class` model, not a `struct`, as documented in the red note [here]({%slug common-features-data-binding-overview%}#how-to-provide-data): +The solution is to always bind the component to a `class` model, not a `struct`. For more information, see [Data Binding Overview]({%slug common-features-data-binding-overview%}#how-to-provide-data).
@@ -98,4 +95,5 @@ The solution is to use a `class` model, not a `struct`, as documented in the red ```` ## See Also + - [Data Binding Overview]({%slug common-features-data-binding-overview%}) \ No newline at end of file