The ParameterView instance can no longer be read because it has expired

Hi,

I have the following error in the Change event of a DropDownDataGrid:

Error: System.InvalidOperationException: The ParameterView instance can no longer be read because it has expired. ParameterView can only be read synchronously and must not be stored for later use.
   at Radzen.ParameterViewExtensions.DidParameterChange[T](ParameterView parameters, String parameterName, T parameterValue)
   at Radzen.DataBoundFormComponent`1.SetParametersAsync(ParameterView parameters)
   at Radzen.DropDownBase`1.SetParametersAsync(ParameterView parameters)
   at Radzen.Blazor.RadzenDropDownDataGrid`1.SetParametersAsync(ParameterView parameters)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

This started happening after version 5.3.5.

Any ideas?

Thanks,
Mike

Any idea where/how to replicate this error?

UPDATE: There is already reproduction code here:

We will release update tomorrow!

Hi -

Just checking if this is fixed - I'm still getting the error.

The ParameterView instance can no longer be read because it has expired.

If this can be solved some other way in my own code, let me know.

Thanks,
Mike

We believe this is fixed - check what version you are using.

Yes, I updated to latest version 5.5.3 to test it.

Mike

Let us know how to replicate the problem using latest version.

Unfortunately as this is very flaky behaviour caused by render timings I do not have a reproduction but I can pinpoint the problematic code:
In SetParametesAsync, the parameters may no longer may accessed after any async call is awaited as they may be invalidated during that time. (https://stackoverflow.com/questions/66717054/the-parameterview-instance-can-no-longer-be-read-because-it-has-expired-paramet)
The error message spefically states that the parameters must only be accessed synchronously.

In DataBoundFormComponent however, if data has changed, OnDataChanged is awaited before the parameters are accessed by DidParameterChange and a subsequent call to base.SetParametersAsync. (radzen-blazor/Radzen.Blazor/DataBoundFormComponent.cs at 68f87db33e54ab3f84053394cfce893e0ca76796 · radzenhq/radzen-blazor · GitHub)
This causes a race condition.

To fix this, the if (dataChanged) { ... } can be moved after base.SetParametersAsync.

MudBlazor experienced a similar problem due to the same issue:

@enchev would you mind taking another look at this issue? It is unfortunately currently holding up development for us. :sweat_smile:

I’m still not sure how to reproduce this. Do you have runnable example? We accept also pull requests!

I'll create a PR then, thanks.

I have created a PR that should resolve this issue:

I've added comments.

Thanks for the quick review and merge! Is there any timeline for the release that will include this fix?

It will be part of our update later today.

1 Like