Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuickGrid throws InvokeAsync exception when RefreshDataAsync() is called #58794

Open
1 task done
ViRuSTriNiTy opened this issue Nov 5, 2024 · 2 comments
Open
1 task done
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one

Comments

@ViRuSTriNiTy
Copy link

ViRuSTriNiTy commented Nov 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hi there,

as the title already states, QuickGrid possibly throws an InvokeAsync exception when RefreshDataAsync() is invoked from a callback associated with a background service, like a timer.

This is caused by a call to StateHasChanged() within RefreshDataAsync() without wrapping it in InvokeAsync as described in https://learn.microsoft.com/en-us/aspnet/core/blazor/components/synchronization-context?view=aspnetcore-8.0#invoke-component-methods-externally-to-update-state.

My current solution is to catch the exception and call StateHasChanged() with InvokeAsync otherwise rethrow:

try
{
    await Grid.RefreshDataAsync();
}
catch (InvalidOperationException ex)
{
    if (ex.Message.Contains("InvokeAsync", StringComparison.Ordinal))
        await InvokeAsync(StateHasChanged);
    else
        throw;
}

Expected Behavior

It would be nice to have await InvokeAsync(StateHasChanged) calls in QuickGrid to avoid the need to use try catches here and there.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Nov 5, 2024
@javiercn
Copy link
Member

javiercn commented Nov 5, 2024

@ViRuSTriNiTy thanks for contacting us.

It's not clear what you are asking. Are you suggesting that RefreshDataAsync internally dispatches the call via InvokeAsync?

@javiercn javiercn added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Nov 5, 2024
@ViRuSTriNiTy
Copy link
Author

@ViRuSTriNiTy thanks for contacting us.

It's not clear what you are asking. Are you suggesting that RefreshDataAsync internally dispatches the call via InvokeAsync?

Exactly, see section Expected behavior:

It would be nice to have await InvokeAsync(StateHasChanged) calls in QuickGrid to avoid the need to use try catches here and there.

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Nov 6, 2024
@javiercn javiercn added this to the .NET 10 Planning milestone Nov 6, 2024
@javiercn javiercn added enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one
Projects
None yet
Development

No branches or pull requests

2 participants