Blazor Grid Custom Adaptor Binding Issue With REST

Hi.

I have been working on solving this issue with Blazor Grid, REST, and CustomAdaptor.

Attached is a copy of the application, and a video showing the issue.

The main issue I am seeing is the error I am getting the first time the grid tries to load. As shown in the video, it works fine after the first time, but also seems to take a different path through the code.


First Time Execution:

------------------------------------------------------------

1. run the application

2. click on the sft_rest_2 option in the menu

3. Code steps into the OnInitiallizeAsyc method - as expected

4. It then make a call to the data service to get all the records

5. Data service the does an http get to the REST api/order endpoint

6. At this point, the Custom Adaptor for the razor page, READ method is called

-in subsequent execution, this is not the next step - you will see the debugger to to the REST controller - that does not happen here


In the output windows I see massages like this - it almost looks like the REST call could not be made. Is this because the Grid object interrupted??


info: System.Net.Http.HttpClient.IOrderDataService.ClientHandler[100]

      Sending HTTP request GET https://localhost:44319/api/order

fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]

      Unhandled exception in circuit 'y8kTfFBxHys8v0T6pkTk4_gzJdF7dt34RKafQvrH_tU'.

System.NullReferenceException: Object reference not set to an instance of an object.

   at Syncfusion.Blazor.Grids.SfGrid`1.GenerateAndExecuteQuery(Query query, Boolean foreignKeyHandle, Boolean isForeignKeyAction, Int32 VirtualStartIndex, Int32 VirtualEndIndex, Boolean isQueryGenerated, Boolean preventForeign)

   at Syncfusion.Blazor.Grids.SfGrid`1.DataProcessChildContent(ActionArgs action, ActionEventArgs`1 actionArgs, Boolean foreignKeyHandle, Boolean isForeignKeyAction)

   at Syncfusion.Blazor.Grids.SfGrid`1.DataProcessChild(ActionArgs action, ActionEventArgs`1 actionArgs)

   at Syncfusion.Blazor.Grids.SfGrid`1.DataProcess(ActionArgs action, ActionEventArgs`1 actionArgs)

   at Syncfusion.Blazor.Grids.SfGrid`1.DataProcess(ActionArgs action, ActionEventArgs`1 actionArgs)

   at Syncfusion.Blazor.Grids.SfGrid`1.OnAfterScriptRendered()

   at Syncfusion.Blazor.SfBaseComponent.InvokeScriptRendered()

   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_0(Object state)

   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteSynchronously(TaskCompletionSource`1 completion, SendOrPostCallback d, Object state)

   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<.cctor>b__23_0(Object state)

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

--- End of stack trace from previous location where exception was thrown ---

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteBackground(WorkItem item)



 7. In the custom adaptor read method, the dataset is not populated, the comes back null.

 8. It then goes back and runs the OnInitiallizeAsyc again, but even though it gets a dataset this time, you will see that that page has now loaded with an error


 Subsequent Executions:

 ------------------------------------------------------------

 The first execution is the only one that fails. After that you will see in the video it progresses in a more expected way. Somehow, on the first execution the HTTP GET seems to get interrupted.



 I am hoping you can shed some light on this issue.


Attachment: SyncfusionBlazorApp.REST_c452516a.7z

3 Replies

JP Jeevakanth Palaniappan Syncfusion Team October 11, 2021 11:32 AM UTC

Hi Marc, 

Greetings from Syncfusion support. Please find the details of your query below. 

Query : Exception when grid rendered for the first time 

We have  checked the attached sample and found that you have returned null in Read method. We would like to inform you that you have to return in the form of Result and Count in the Read method of custom adaptor. The exception is due to this null return value. If you return with proper Result and Count then the exception will not occur. 

            public override object Read(DataManagerRequest dm, string key = null) 
            { 
                IEnumerable<Order> DataSource = Orderz; 
 
                if ( Orderz == null){ 
                    return null; 
                } 
} 

Query : The flow of execution is different 

We suspect that the data is not fetched in asynchronously way. The below GetAll method is synchronously executed. So we suggest you to check the problem by changing all the methods to execute asynchronously.  

 

Also you can use the ReadAsync method instead of Read method if you need it asynchronously. Please refer the below documentation for your reference. 

Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 



MA Marc October 11, 2021 10:17 PM UTC

The main question I have, is should Orderz  be null the first time through?  You have suggested 2 possible solutions, in your estimation, which is the best way to approach this?  Is this issue related to the async read?



JP Jeevakanth Palaniappan Syncfusion Team October 12, 2021 06:51 AM UTC

Hi Marc, 
 
Query: is should Orderz  be null the first time through 
 
We suspect that the Orderz is null due to which the data is not fetched in asynchronous way. So kindly change all your methods to work asynchronously. As of now, you can use the Read method itself since there is no async method call inside the read method. We have shared the ReadAsync documentation to let you know incase in future if you use/invoke any async method inside the Read method, you can use the ReadAsync method instead of Read method. 
 
Please get back to us if you have any other queries. 
 
Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon