multilanguages icon indicating copy to clipboard operation
multilanguages copied to clipboard

The current thread is not associated with the Dispatcher

Open EugenePok opened this issue 4 years ago • 4 comments

Hello, I will get the following errors in BlazorExtension.cs line 33. I believe this might related to StateHasChanged must be invoke asynchronously?

This does not happen every time but only happens after I close the tab and open again. Any suggestion on how to solve it? image

EugenePok avatar Mar 19 '21 09:03 EugenePok

Thank you so much for reaching out I will make sure to debug it and get it fixed now I will get back to you in minutes

aksoftware98 avatar Mar 19 '21 09:03 aksoftware98

I tried something like this and it worked! But I think we need to change the way we get InvokeAsync method because currently im still studying how to get the correct method if there exist overloaded method.

var action = new Action<object>(e =>
{
    // Call the StateHasChanged function for the component 
    var type = typeof(ComponentBase);
    var stateHasChangedMethod = type.GetMethod("StateHasChanged", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    var InvokeAsync = type.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Where(m=> m.Name =="InvokeAsync").FirstOrDefault();
    Object[] addHandlerArgs = { stateHasChangedMethod.CreateDelegate<Action>(extension.Component) };
    InvokeAsync.Invoke(extension.Component, addHandlerArgs);
});

EugenePok avatar Mar 19 '21 10:03 EugenePok

I'm wondering if you can please share your sample that throws the error with me so maybe this will easier to debug and reproduce the issue

thank you

aksoftware98 avatar Mar 19 '21 10:03 aksoftware98

I have this same issue and have code that reproduces this exact error: https://github.com/TcNobo/TcNo-Acc-Switcher/commit/f966a02571d485cb87e385b948ec747fce844206 [Browse files link] [ Testing ] Set TcNo-Acc-Switcher-Server to IIS Express, on the main page click the Settings icon in the bottom right. Change the language using the first dropdown, and it errors out. Exactly the same as above.

I would say build TcNo-Acc-Switcher-Client and test with that, as you can see the console as well as the browser window - but you'll need 3 runtimes installed: WebView2 and both the ones from clicking Download x64 AND Download Hosting Bundle on this page [Microsoft .NET 5 Desktop Runtime AND: ASP.NET Core 5.0 Runtime]

Had this issue because I wanted localisation, but can't use the default one due to the project having the assembly name TcNo-Acc-Switcher-Server and namespace of "TcNo_Acc_Switcher_Server" - so it just doesn't read the .resx files until they both match (See: temp-localisation branch). No matter what I try I can't get it to work properly. This NuGet package works great, just struggling with changing it.

TCNOco avatar Jun 09 '21 13:06 TCNOco

Sorry for the late response.

But v5.8 and the latest version of the Blazor library resolve this issue make sure to use the new registration method in your dependency injection container in the documentation here in the following link: What's new in Version 5.8

Just make sure please to upgrade your library to the latest version as Blazor Server right now is fully supported in the process

aksoftware98 avatar Oct 05 '22 06:10 aksoftware98