I have a grid correctly displaying columns automatically from a data table, using a dynamic type. However it seems there is a strange casting error in the Grid.OnAfterRenderAsync call inside Syncfusion which causes the page to no longer respond after rendering out the grid data.
I am using version 17.3.0.27-beta and .NET core 3.1.0-preview3.19553.2 and linking to scripts like this:
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DKHTracker</title>
<base rel='nofollow' href="~/" />
<link rel="stylesheet" rel='nofollow' href="css/bootstrap/bootstrap.min.css" />
<link rel='nofollow' href="css/site.css" rel="stylesheet" />
<link rel='nofollow' href="https://cdn.syncfusion.com/ej2/17.3.27/material.css" rel="stylesheet" />
<script src="https://cdn.syncfusion.com/ej2/17.3.27/dist/ej2.min.js"></script>
<script src="https://cdn.syncfusion.com/ej2/17.3.27/dist/ejs.interop.min.js"></script>
</head>
Here is the sample code:
<EjsGrid DataSource="@CustomerList" Height="500">
</EjsGrid>
@code {
public List<dynamic> CustomerList = new List<dynamic>();
override protected async Task OnInitializedAsync() {
DataTable dt = await Sql.Query("SELECT id, name, email FROM customer ORDER BY name");
foreach (DataRow row in dt.Rows)
CustomerList.Add(new Sql.DynamicDataRow(row));
}
}
And the dynamic object is:
public class DynamicDataRow : DynamicObject {
private readonly DataRow row;
public DynamicDataRow(DataRow row) {
this.row = row;
}
public override bool TryGetMember(GetMemberBinder binder, out object result) {
DataColumn column = row.Table.Columns[binder.Name];
if (column != null) {
result = row[column];
return true;
}
result = null;
return false;
}
public override IEnumerable<string> GetDynamicMemberNames() {
var names = row.Table.Columns.Cast<DataColumn>().Select(x => x.ColumnName);
return names;
}
}
I get the following error:
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
Unhandled exception rendering component: Unable to cast object of type 'Sy
stem.String' to type 'System.Collections.Generic.List`1[Syncfusion.EJ2.Blazor.Gr
ids.GridColumn]'.
System.InvalidCastException: Unable to cast object of type 'System.String' to ty
pe 'System.Collections.Generic.List`1[Syncfusion.EJ2.Blazor.Grids.GridColumn]'.
at Syncfusion.EJ2.Blazor.Grids.EjsGrid`1.OnAfterRenderAsync(Boolean firstRend
er)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'bQ6RWWW8xlzMDA9GKbyEsGoVl6I6DCoL1pfgkFfzWK
k'.
System.AggregateException: One or more errors occurred. (Unable to cast object o
f type 'System.String' to type 'System.Collections.Generic.List`1[Syncfusion.EJ2
.Blazor.Grids.GridColumn]'.)
---> System.InvalidCastException: Unable to cast object of type 'System.String'
to type 'System.Collections.Generic.List`1[Syncfusion.EJ2.Blazor.Grids.GridColu
mn]'.
at Syncfusion.EJ2.Blazor.Grids.EjsGrid`1.OnAfterRenderAsync(Boolean firstRend
er)
Is this a bug in the current version, or am I doing something wrong? In previous versions i think this code worked ok.