Error on Blazor grid very simple binding
This is my code
@if (products != null)
{
<SfGrid DataSource="@products" TValue="Product">
<GridColumns>
<GridColumn Field="Name" HeaderText="Name" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field="ProductName" HeaderText="Number" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
}
@code {
List<Product> products=new List<Product>();
protected override void OnInitialized()
{
base.OnInitialized();
products.Add(new Product { Name = "Books" });
products.Add(new Product { Name = "Electronics" });
}
protected void ButtonClicked()
{
}
}
This is the error i got
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: E:\Learn\BlazorApp5\BlazorApp5
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.CreateAccessor(PropertyInfo propertyInfo)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetAccessor(String name, IDictionary`2 cache, Object from)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetFieldValue(String nameSpace, Object from, IDictionary`2 cache)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetObject(String nameSpace, Object from)
at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.GetValue()
at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'Czj_SDx-nXr_Q7DZS6aQu_ybvAXrCh1NEzwhW7PpXj4'.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.CreateAccessor(PropertyInfo propertyInfo)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetAccessor(String name, IDictionary`2 cache, Object from)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetFieldValue(String nameSpace, Object from, IDictionary`2 cache)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetObject(String nameSpace, Object from)
at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.GetValue()
at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
Unhandled exception rendering component: Cannot access a disposed object.
System.ObjectDisposedException: Cannot access a disposed object.
at Microsoft.AspNetCore.Components.RenderTree.ArrayBuilder`1.ThrowObjectDisposedException()
at Microsoft.AspNetCore.Components.RenderTree.ArrayBuilder`1.GrowBuffer(Int32 desiredCapacity)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit 'Czj_SDx-nXr_Q7DZS6aQu_ybvAXrCh1NEzwhW7PpXj4'.
System.ObjectDisposedException: Cannot access a disposed object.
at Microsoft.AspNetCore.Components.RenderTree.ArrayBuilder`1.ThrowObjectDisposedException()
at Microsoft.AspNetCore.Components.RenderTree.ArrayBuilder`1.GrowBuffer(Int32 desiredCapacity)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
SIGN IN To post a reply.
10 Replies
1 reply marked as answer
JP
Jeevakanth Palaniappan
Syncfusion Team
November 3, 2020 10:41 AM UTC
Hi Amr,
Greetings from Syncfusion support.
We have validated your query by using the provided code snippet in Latest Syncfusion Nuget version (18.3.0.44). But unfortunately, we are unable to reproduce the reported issue from our end. So we suggest you to check the issue in the latest version. We have attached the validated sample below for your reference.
Sample - https://www.syncfusion.com/downloads/support/directtrac/general/ze/TestSyncfusionDataGrid2043226320
Please get back to us if you need further assistance.
Regards,
Jeevakanth SP.
YA
yanshifu
January 7, 2021 06:10 AM UTC
I get some same issue when binding data using syncfusion blazor.
As blow...
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.CreateAccessor(PropertyInfo propertyInfo)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetAccessor(String name, IDictionary`2 cache, Object from)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetFieldValue(String nameSpace, Object from, IDictionary`2 cache)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetObject(String nameSpace, Object from)
at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.GetValue()
at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit '1Ojl5yl9VyKm2mYzDuWqPVvhfmcIy_UkzCDklQeRWl0'.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.CreateAccessor(PropertyInfo propertyInfo)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetAccessor(String name, IDictionary`2 cache, Object from)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetFieldValue(String nameSpace, Object from, IDictionary`2 cache)
at Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetObject(String nameSpace, Object from)
at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.GetValue()
at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
Unhandled exception rendering component: Cannot access a disposed object.
System.ObjectDisposedException: Cannot access a disposed object.
at Microsoft.AspNetCore.Components.RenderTree.ArrayBuilder`1.ThrowObjectDisposedException()
at Microsoft.AspNetCore.Components.RenderTree.ArrayBuilder`1.GrowBuffer(Int32 desiredCapacity)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
JP
Jeevakanth Palaniappan
Syncfusion Team
January 8, 2021 07:35 AM UTC
Hi Yanshifu,
We tried to reproduce the reported problem by using a simple code example but we are unable to reproduce the reported problem. We have attached a video demonstration and the validated sample for your reference.
Sample - https://www.syncfusion.com/downloads/support/directtrac/general/ze/TestSyncfusionDataGrid931970088
Kindly check the issue in the updated Syncfusion NuGet version. If you still face the reported problem then kindly share us the following details,
- Share us the complete grid rendering code, model class and datasource.
- If possible kindly share us the issue reproducing sample or reproduce the issue in the provided sample.
Regards,
Jeevakanth SP.
AM
Amr
January 8, 2021 08:31 AM UTC
My problem was that there was a field name in the grid definition that was not in the object i am binding to .
Hope this helps .
JP
Jeevakanth Palaniappan
Syncfusion Team
January 11, 2021 11:56 AM UTC
Hi Amr,
We would like to let you know that the grid is a strongly typed component in which we will process grid column fields only based on the model class properties. So you cannot set column fields which is not present in the model class.
Please get back to us if you have any other queries.
Regards,
Jeevakanth SP.
Marked as answer
MC
Matt Carlucci
January 27, 2021 05:00 PM UTC
I'm getting the same error. Very simple binding. Version 18.4.0.35
@if (StockDetails != null)
{
<SfGrid ID="Grid" DataSource="@StockDetails" @ref="Grid"
Height="100%" Width="100%">
<GridColumns>
<GridColumn Field=@nameof(Models.StockChartData.Date) HeaderText="Date" Width="50"></GridColumn>
<GridColumn Field=@nameof(Models.StockChartData.High) HeaderText="High" Format="C0" Width="50"></GridColumn>
<GridColumn Field=@nameof(Models.StockChartData.Low) HeaderText="Low" Format="C0" Width="50"></GridColumn>
<GridColumn Field=@nameof(Models.StockChartData.Close) HeaderText="Close" Format="C0" Width="50"></GridColumn>
</GridColumns>
</SfGrid>
}
MC
Matt Carlucci
January 27, 2021 05:09 PM UTC
I could not edit the original post
NullReferenceException: Object reference not set to an instance of an object.
Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.CreateAccessor(PropertyInfo propertyInfo)
Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetAccessor(string name, IDictionary<string, IPropertyAccessor> cache, object from)
Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetFieldValue(string nameSpace, object from, IDictionary<string, IDictionary<string, IPropertyAccessor>> cache)
Syncfusion.Blazor.Grids.Internal.PropertyInfoHelper.GetObject(string nameSpace, object from)
Syncfusion.Blazor.Grids.Internal.GridCellBase<TCell>.GetValue()
Syncfusion.Blazor.Grids.Internal.GridCellBase<TCell>.OnParametersSetAsync()
Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(ref DiffContext diffContext, int frameIndex)
Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(ref DiffContext diffContext, int frameIndex)
Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(ref DiffContext diffContext, int newFrameIndex)
Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(ref DiffContext diffContext, int oldStartIndex, int oldEndIndexExcl, int newStartIndex, int newEndIndexExcl)
Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, int componentId, ArrayRange<RenderTreeFrame> oldTree, ArrayRange<RenderTreeFrame> newTree)
Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessPendingRender()
Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(int componentId, RenderFragment renderFragment)
Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged()
Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderRootComponentAsync(int componentId, ParameterView initialParameters)
Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.CreateInitialRenderAsync(Type componentType, ParameterView initialParameters)
Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.RenderComponentAsync(Type componentType, ParameterView initialParameters)
Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext+<>c__11<TResult>+<<InvokeAsync>b__11_0>d.MoveNext()
Microsoft.AspNetCore.Mvc.ViewFeatures.StaticComponentRenderer.PrerenderComponentAsync(ParameterView parameters, HttpContext httpContext, Type componentType)
Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.PrerenderedServerComponentAsync(HttpContext context, ServerComponentInvocationSequence invocationId, Type type, ParameterView parametersCollection)
Microsoft.AspNetCore.Mvc.ViewFeatures.ComponentRenderer.RenderComponentAsync(ViewContext viewContext, Type componentType, RenderMode renderMode, object parameters)
Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, int i, int count)
Portfolio.Pages.Pages__Host.<ExecuteAsync>b__14_1() in
_Host.cshtml- <component type="typeof(Portfolio.Manager.App)" render-mode="ServerPrerendered" />
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.SetOutputContentAsync()
Portfolio.Pages.Pages__Host.ExecuteAsync() in
_Host.cshtml- Layout = null;
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
MC
Matt Carlucci
January 27, 2021 08:02 PM UTC
Check to make sure you've defined properties and not backing fields.
Public DateTime Date; //; will produce an error as Syncfusion may be treating/expecting this as a property
Public DateTime Date {get;set;} should eliminate the error.
MC
Matt Carlucci
January 27, 2021 08:03 PM UTC
Check to make sure you've defined properties and not backing fields.
Public DateTime Date; //; will produce an error as Syncfusion may be treating/expecting this as a property
Public DateTime Date {get;set;} should eliminate the error.
MC
Matt Carlucci
January 27, 2021 08:03 PM UTC
Check to make sure you've defined properties and not backing fields.
Public DateTime Date; //; will produce an error as Syncfusion may be treating/expecting this as a property
Public DateTime Date {get;set;} should eliminate the error.
SIGN IN To post a reply.