Cannot Access a Disposed Object Error

Hi all,

I am working with .Net 5.0 & Blazor and, when trying to Refresh a grid, using Grid.Refresh(), I get the following error:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Cannot access a disposed object.
      Object name: 'DotNetObjectReference`1'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'DotNetObjectReference`1'.
   at Microsoft.JSInterop.DotNetObjectReference`1[[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ThrowIfDisposed()
   at Microsoft.JSInterop.JSRuntime.TrackObjectReference[Object](DotNetObjectReference`1 dotNetObjectReference)
   at Microsoft.JSInterop.Infrastructure.DotNetObjectReferenceJsonConverter`1[[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Write(Utf8JsonWriter writer, DotNetObjectReference`1 value, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1[[Microsoft.JSInterop.DotNetObjectReference`1[[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Microsoft.JSInterop, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryWrite(Utf8JsonWriter writer, DotNetObjectReference`1& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[Microsoft.JSInterop.DotNetObjectReference`1[[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Microsoft.JSInterop, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].TryWriteAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Object& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.ArrayConverter`2[[System.Object[], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnWriteResume(Utf8JsonWriter writer, Object[] value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.IEnumerableDefaultConverter`2[[System.Object[], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnTryWrite(Utf8JsonWriter writer, Object[] value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object[], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, Object[]& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Object[], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, Object[]& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.JsonSerializer.WriteCore[Object[]](JsonConverter jsonConverter, Utf8JsonWriter writer, Object[]& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.JsonSerializer.WriteCore[Object[]](Utf8JsonWriter writer, Object[]& value, Type inputType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Serialize[Object[]](Object[]& value, Type inputType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Serialize[Object[]](Object[] value, JsonSerializerOptions options)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[String](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__15`1[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Syncfusion.Blazor.Popups.SfTooltip.OnAfterScriptRendered()
   at Syncfusion.Blazor.SfBaseComponent.OnAfterRenderAsync(Boolean firstRender)
   at Syncfusion.Blazor.Popups.SfTooltip.OnAfterRenderAsync(Boolean firstRender)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

I have stepped through my code in Visual Studio and the error only appears after I step over the "Grid.Refresh();" line.

Also, I currently receive multiple copies of the same error (see table below). 

On my page I have 3 grids, 1 normal & 2 headerless. In one error scenario, the normal grid has 161 rows, one headerless grid has 14 rows and the other has 1 row.

My "normal" grid is set up as follows:

<SfGrid @ref="@Grid" DataSource="@versions1" AllowTextWrap="true" AllowSorting="true" AllowPaging="true">
    <GridPageSettings PageSize="10"></GridPageSettings>
    <GridEvents CommandClicked="CommandClickHandler" RowSelected="RowSelectHandler" OnActionFailure="ActionFailureHandler" TValue="Version1"></GridEvents>
    <GridSortSettings>
        <GridSortColumns>
            <GridSortColumn Field="ReleaseDate" Direction="SortDirection.Descending"></GridSortColumn>
        </GridSortColumns>
    </GridSortSettings>

and, my other two are almost identical:

                <SfGrid ID="GridSys"
                        @ref="@SysGrid"
                        DataSource="@dispSys"
                        TValue="DispSys"
                        AllowTextWrap="true"
                        AllowSorting="false"
                        AllowPaging="true"
                        AllowSelection="false">
                    <GridSortSettings>
                        <GridSortColumns>
                            <GridSortColumn Field="Manufacturer" Direction="SortDirection.Ascending"></GridSortColumn>
                            <GridSortColumn Field="Name" Direction="SortDirection.Descending"></GridSortColumn>
                        </GridSortColumns>
                    </GridSortSettings>
                    <GridPageSettings PageSize="5"></GridPageSettings>
                    <GridEvents OnActionFailure="ActionFailureHandler" TValue="DispSys"></GridEvents>

These errors occur every time I visit a page with a large amount of data:

Main Grid     Headerless1     Headerless2          Error
6 rows           1 row                 1 row                      No
161 rows       14 rows              1 row                     Yes (168x)
30 rows         10 rows              1 row                     Yes (45x) 

NB: All data is returned & displayed correctly in all of the above scenarios.

Does anyone have any idea why this is happening? and, how I can stop it happening?

Thank in advance

Simon

10 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team October 22, 2020 04:41 PM UTC

Hi Simon, 

Greetings from Syncfusion. 

Query: Cannot Access a Disposed Object Error - I am working with .Net 5.0 & Blazor and, when trying to Refresh a grid, using Grid.Refresh(), I get the following error: 

We have validated your query with the provided information. We have prepared a sample based on your shared information(1 normal & 2 header less) and checked the reported problem at our end. While performing refresh action of the Grid, we could not reproduce the problem at our end. Find the sample for your reference. 


If you are still facing  the problem, could you please share the below information. It will be helpful to validate and provide a better solution. 

  • Full code snippets of the Grid.
  • Model class details.
  • Reproduce the problem in the provided sample and revert back to us.
  • Share a simple reproduceable sample if possible.

Regards, 
Rahul 


Marked as answer

SI Simon October 23, 2020 04:04 AM UTC

Hi Rahul,

Thanks for the reply.

I don't think I can generate a small reproducible sample as I am using Authorisation, Services etc.

Is there any way I can give you direct access to the codebase without publishing the link on the forum?

Thanks in advance

Simon

EDIT:

I think I may have worked out what is wrong...

I have carried out some further testing and noticed that the errors ONLY occur where there are multiple pages in a grid.

For example, the following errored:

3DNes           4 Errors 14 rows in bottom grid (10 to a page)
1964           44 Errors 54 rows in bottom grid (10 to a page)
AdvanceMAME   168 Errors 161 rows in top left grid (5 to a page), 14 rows in bottom grid (10 to a page)

From the above, I have come to the conclusion that the number of errors equates to the number of NON-VISIBLE IMAGES(i.e. images on the second and subsequent pages of the grid).

In '3DNes' & '1964', each row has ONE image. So, there are 4 errors (the number of rows with images not displayed) for '3DNes' and 44 errors (the number of rows with images not displayed) for '1964'.

With 'AdvanceMAME', there are 156 rows with images that are not displayed in the top left grid (ONE image per row) and 4 rows with images not displayed in the bottom grid. However, each of the 4 rows in the bottom grid have THREE images each (i.e. 12 images total). Adding 156 and 12 gives 168.

When I move between the pages, all of the images are displayed correctly, so I'm not sure what, exactly, is occurring.

Hope this helps

Simon


TD Tom Dimos October 23, 2020 01:13 PM UTC

I get the same error but in a different situation. I have a page with a Grid and with a button I move to another page.Then if I move back(to the page with the grid which is fetching my data) and then move again to the other page fast enough I get this error. If I wait a bit(2-3 secs) after the spinner dissapears it works as expected.So this must be a problem with the Grid trying to refresh(or something like that) even if it is disposed.Maybe a javascript call can't get canceled.


RN Rahul Narayanasamy Syncfusion Team October 27, 2020 02:19 PM UTC

Hi Simon & Tom, 

We have validated your with the provided information at our end. We have checked the exception and the exception was thrown from tooltip. So we need some information regarding the reported problem. Could you please share the below details. It will be more helpful to validate and provide a better solution. 

  • Did you used SfTooltip in Grid(like in column template, header template, etc)?
  • Did you used SfTooltip in that particular page?
  • Share complete code snippets of the page.
  • Video demonstration of the problem.

Regards, 
Rahul 



TD Tom Dimos October 27, 2020 02:59 PM UTC

Yes I am using SfToolTip inside a <Template> tag.


SI Simon October 27, 2020 09:03 PM UTC

Same here.

My code is as follows:

        <GridColumn Field="SysDatas" HeaderText="Emulated System(s)" AllowSorting="false" AllowFiltering="false">
            <Template>
                @{
                    var t = (context as EmuData);

                    if (t.SysDatas.Count <= 2)
                    {
                        <div class="flex item__container">
                            @{
                                foreach (var p in t.SysDatas)
                                {
                                    var imageUrl = p.Picture;
                                    var name = p.Name;
                                    var mfr = p.Manufacturer;
                                    var sTxt = mfr + " " + name;

                                    <SfTooltip Content="@sTxt" CssClass="inlineclass">
                                        <img src="@imageUrl" alt="@name" width="75" height="50" />
                                    </SfTooltip>
                                }
                            }
                        </div>
                    }
                    else
                    {
                        <div>More than 2 Systems</div>
                    }
                }
            </Template>
        </GridColumn>

Hope that helps

Simon


RN Rahul Narayanasamy Syncfusion Team October 28, 2020 12:20 PM UTC

Hi Simon & Tom, 

Thanks for the update. 

We have checked your reported issue with Tooltip component. We are able to reproduce  the problem at our end and this is already an known issue from our end. We will include this fix in first patch release after Vol3 SP release which is expected to be rolled out by mid of November 2020. 
  
Please, track the following feedback link to know the status of this fix.  
 
 
We appreciate your patience. 
 
Regards, 
Rahul 



DO Doug December 12, 2021 06:17 AM UTC

I get this same error with a very simple sfGrid,/19.3.0.57 clicking a row produces:


With a GridTemplate.DetailTemplate:


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, Exception& renderFragmentException)

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()


Without (no detail)


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

at Syncfusion.Blazor.Grids.Internal.Selection`1.SelectByRow(Row`1 rowToSelect, MouseAndKeyArgs evt)

at Syncfusion.Blazor.Grids.Internal.Selection`1.ValidateRowSelectionClick(Row`1 row, MouseAndKeyArgs e)

at Syncfusion.Blazor.Grids.Internal.Selection`1.RowSelectionClickHandler(MouseAndKeyArgs e, ValueTuple`3 target)

at Syncfusion.Blazor.Grids.Internal.Selection`1.ClickHandler(MouseEventArgs e, ValueTuple`3 target)

at Syncfusion.Blazor.Grids.Internal.GridCellBase`1.CellClickHandler(MouseEventArgs e, Boolean IsCheckBox)

at Syncfusion.Blazor.Grids.Internal.GridCell`1.b__0_1(MouseEventArgs e)

at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)




RN Rahul Narayanasamy Syncfusion Team December 13, 2021 02:08 PM UTC

Hi Doug, 

Greetings from Syncfusion. 

Query: I get this same error with a very simple sfGrid,/19.3.0.57 clicking a row produces: With a GridTemplate.DetailTemplate: System.ObjectDisposedException: Cannot access a disposed object. 
 
We have validated your query and checked the reported case at our end. We could not face the reported problem with detail template. While clicking the row, the second reported problem only reproduced at our end. Find the sample for your reference. 


So we need more details regarding the reported problem. Could you please share the below details. It will be helpful to validate and provide a better solution. 

  • Full Grid code snippets.
  • Whether did you used Server side application of WebAssembly application?
  • Reproduce the problem in the provided sample and revert back to us.
  • Share a simple reproduceable sample if possible.

Query: Without (no detail) System.NullReferenceException: Object reference not set to an instance of an object. at Syncfusion.Blazor.Grids.Internal.Selection`1.SelectByRow(Row`1 rowToSelect, MouseAndKeyArgs evt) 
 
We have validated your query and we have already confirmed this as an issue and logged the defect report “NullReference Exception throws when selecting a row in grid for the same. Thank you for taking time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and including the fix in our upcoming bi-weekly release which is expected to be rolled out on or before the mid of December 2021. We will update you once the release is rolled out.      
         
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.  
 

Regards, 
Rahul 




RN Rahul Narayanasamy Syncfusion Team December 20, 2021 11:59 AM UTC

Hi Doug, 
 
We are glad to announce that our weekly patch release (v19.3.0.59) has been rolled out successfully and in this release, we have included the fix for the issue NullReference Exception throws when selecting a row in grid”. So kindly update your NuGet to our latest version to resolve the reported issue. 
 
Please find the NuGet package below 
 
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.  
 
Regards, 
Rahul 


Loader.
Up arrow icon