Hi everyone,
I'm having trouble understanding why I can't use an immutable array in the Data property of RadzenDataGrid. Since it implements IEnumerable, I expected it to work. Could someone please explain why this is not possible ?
Thank you!
Hi everyone,
I'm having trouble understanding why I can't use an immutable array in the Data property of RadzenDataGrid. Since it implements IEnumerable, I expected it to work. Could someone please explain why this is not possible ?
Thank you!
Hi everyone,
I'm detailing my previous post.I've looked into the code, but I'm having trouble understanding the issue because the parameter is an IEnumerable
, and ImmutableArray
implements IEnumerable
.
Example Code:
<RadzenDataGrid AllowVirtualization="true" PageSize="2" Data="@Items" EmptyText="Empty"
AllowPaging="true" TItem="CustomClass" AllowFiltering="true" AllowSorting="true">
<Columns>
<RadzenDataGridColumn TItem="CustomClass" Property="@nameof(CustomClass.Name)" />
<RadzenDataGridColumn TItem="CustomClass" Property="@nameof(CustomClass.Description)" />
</Columns>
</RadzenDataGrid>
@code {
public class CustomClass
{
public CustomClass(string name, string description)
{
Name = name;
Description = description;
}
public string Name { get; set; }
public string Description { get; set; }
}
private ImmutableArray<CustomClass> Items = ImmutableArray.Create(
new CustomClass("test1", "description test1"),
new CustomClass("test2", "description test2"),
new CustomClass("test3", "description test3"),
new CustomClass("test4", "description test4")
);
}
Exception thrown during render:
blazor.web.js:1 [2025-04-24T12:18:54.608Z] Error: System.ArgumentException: Expression of type 'System.Collections.Immutable.ImmutableArray`1[CustomClass]' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[CustomClass]' of method 'Int32 Count[CustomClass](System.Collections.Generic.IEnumerable`1[CustomClass])' (Parameter 'arg0')
at Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize`1.BuildRenderTree(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)