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

ConfigureAwait(false) in Effect results in exception #20

Closed
JEnrightDev opened this issue Apr 23, 2020 · 3 comments · Fixed by #21
Closed

ConfigureAwait(false) in Effect results in exception #20

JEnrightDev opened this issue Apr 23, 2020 · 3 comments · Fixed by #21

Comments

@JEnrightDev
Copy link

When implementing an effect, if you return from a sub-task with ConfigureAwait(false), you will be greeted with a lovely exception.

The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.

   at Microsoft.AspNetCore.Components.Dispatcher.AssertAccess()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged()
   at Fluxor.Blazor.Web.Components.FluxorComponent.<OnInitialized>b__3_0(IState _)
   at Fluxor.Blazor.Web.Components.StateSubscriber.<>c__DisplayClass2_1.<Subscribe>b__1(Object s, EventArgs a)
   at Fluxor.Feature`1.TriggerStateChangedCallbacks(TState newState)
   at Fluxor.Feature`1.set_State(TState value)
   at Fluxor.Store.DequeueActions()
   at Fluxor.Store.Dispatch(Object action)
   at ....my-project..../GlobalStore.cs:line 62

Simple Example:

                [EffectMethod]
                protected async Task HandleEffect(LoadAllTaskSettingsAction action, IDispatcher dispatcher)
                {
                    try
                    {
                        dispatcher.Dispatch(new Update("Handling effect for LoadAllTaskSettingsAction"));

                        dispatcher.Dispatch(new Success(await _settings.GetAllSettingsAsync().ConfigureAwait(false)));
                    }
                    catch (Exception ex)
                    {
                        dispatcher.Dispatch(new Failure(ex));
                    }
                }
@mrpmorris
Copy link
Owner

I'll look at it, thanks

@mrpmorris
Copy link
Owner

There is a preview release that fixes this. Would you like to try it?

@JEnrightDev
Copy link
Author

There is a preview release that fixes this. Would you like to try it?

Looks like it works now. Thanks!

@mrpmorris mrpmorris linked a pull request May 6, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants