DropDownBase - BlazorHybrid - LoadData in DebounceFilter throws dispatcher error #1875

Closed
opened 2026-01-29 17:59:40 +00:00 by claunia · 3 comments
Owner

Originally created by @joriverm on GitHub (Sep 26, 2025).

Describe the bug
Our application can run both in browser and in a Webview2 inside a WPF application, making it a hybrid application.
In the browser (server rendering) filtering in the RadzenDropdown works fine, but in WPF we get a InvalidOperationException saying 'The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.'.
The StackTrace is useless, as its just this :

   at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged() in Microsoft.AspNetCore.Components\ComponentBase.cs:line 81

However, the CallStack paints us a cleaner picture :

 	[System.InvalidOperationException thrown]	
 	[Managed to Native Transition]	
>	Microsoft.AspNetCore.Components.dll!Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged() Line 81	C#
 	Microsoft.AspNetCore.Components.dll!Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, object arg) Line 216	C#
 	Microsoft.AspNetCore.Components.dll!Microsoft.AspNetCore.Components.EventCallback<Radzen.LoadDataArgs>.InvokeAsync(Radzen.LoadDataArgs arg) Line 112	C#
 	Radzen.Blazor.dll!Radzen.DropDownBase<Substance>.DebounceFilter()	Unknown
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.Task>.InnerInvoke()	Unknown
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread)	Unknown
 	System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()	Unknown
 	System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()	Unknown

It shows that its trying to do a StateHasChanged after invoking the eventcallback of LoadData here : https://github.com/radzenhq/radzen-blazor/blob/master/Radzen.Blazor/DropDownBase.cs#L847

What i dont get is why its only failing on WPF and why it fails there.
despite my instinct shouting no, if i incase the callback with a InvokeAsync it works, but fails a bit later with the same problem : https://github.com/radzenhq/radzen-blazor/blob/master/Radzen.Blazor/DropDownBase.cs#L855

I dont understand why its doing what its doing, so i hope somebody else can help me out here. i'd like to make a PR with a fix soon, but unsure what the correct fix is here

To Reproduce
Create Wpf hybrid application and use radzen dropdown in the blazor code. start a filter
Sorry, we weren't able to make a test app just yet :/

Expected behavior
filter to work in wpf

Screenshots
crash/exception

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser WebView2 ( Edge)
  • Version : 7.4.2
Originally created by @joriverm on GitHub (Sep 26, 2025). **Describe the bug** Our application can run both in browser and in a Webview2 inside a WPF application, making it a hybrid application. In the browser (server rendering) filtering in the RadzenDropdown works fine, but in WPF we get a InvalidOperationException saying 'The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.'. The StackTrace is useless, as its just this : ``` at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged() in Microsoft.AspNetCore.Components\ComponentBase.cs:line 81 ``` However, the CallStack paints us a cleaner picture : ``` [System.InvalidOperationException thrown] [Managed to Native Transition] > Microsoft.AspNetCore.Components.dll!Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged() Line 81 C# Microsoft.AspNetCore.Components.dll!Microsoft.AspNetCore.Components.ComponentBase.Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, object arg) Line 216 C# Microsoft.AspNetCore.Components.dll!Microsoft.AspNetCore.Components.EventCallback<Radzen.LoadDataArgs>.InvokeAsync(Radzen.LoadDataArgs arg) Line 112 C# Radzen.Blazor.dll!Radzen.DropDownBase<Substance>.DebounceFilter() Unknown System.Private.CoreLib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.Task>.InnerInvoke() Unknown System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread) Unknown System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Unknown System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() Unknown ``` It shows that its trying to do a StateHasChanged after invoking the eventcallback of LoadData here : https://github.com/radzenhq/radzen-blazor/blob/master/Radzen.Blazor/DropDownBase.cs#L847 What i dont get is why its only failing on WPF and why it fails there. despite my instinct shouting no, if i incase the callback with a `InvokeAsync` it works, but fails a bit later with the same problem : https://github.com/radzenhq/radzen-blazor/blob/master/Radzen.Blazor/DropDownBase.cs#L855 I dont understand why its doing what its doing, so i hope somebody else can help me out here. i'd like to make a PR with a fix soon, but unsure what the correct fix is here **To Reproduce** Create Wpf hybrid application and use radzen dropdown in the blazor code. start a filter Sorry, we weren't able to make a test app just yet :/ **Expected behavior** filter to work in wpf **Screenshots** crash/exception **Desktop (please complete the following information):** - OS: Windows 11 - Browser WebView2 ( Edge) - Version : 7.4.2
Author
Owner

@enchev commented on GitHub (Sep 26, 2025):

There isn't any StateHasChanged in our code:

Image

If you handle LoadData make sure you don't have

@enchev commented on GitHub (Sep 26, 2025): There isn't any StateHasChanged in our code: <img width="1920" height="1080" alt="Image" src="https://github.com/user-attachments/assets/d3994963-0a89-467c-ab60-4f76fc548859" /> If you handle LoadData make sure you don't have
Author
Owner

@joriverm commented on GitHub (Sep 26, 2025):

neither does our code, as you can tell from the callstack its not even in our code, it comes from Blazor itself. EventCallback's InvokeAsync does call statehaschanged and the LoadData is a EventCallback sooo...

you call invokeasync ( 8cf9c5bcd0/src/Components/Components/src/EventCallback.cs (L60) ) which calls ComponentBase's HandleEventAsync which calls StateHasChanged ( 8cf9c5bcd0/src/Components/Components/src/ComponentBase.cs (L364) )

@joriverm commented on GitHub (Sep 26, 2025): neither does our code, as you can tell from the callstack its not even in our code, it comes from Blazor itself. EventCallback's InvokeAsync does call statehaschanged and the LoadData is a EventCallback sooo... you call invokeasync ( https://github.com/dotnet/aspnetcore/blob/8cf9c5bcd03b84202b234cf515c2e3057b621a14/src/Components/Components/src/EventCallback.cs#L60 ) which calls ComponentBase's HandleEventAsync which calls StateHasChanged ( https://github.com/dotnet/aspnetcore/blob/8cf9c5bcd03b84202b234cf515c2e3057b621a14/src/Components/Components/src/ComponentBase.cs#L364 )
Author
Owner

@joriverm commented on GitHub (Sep 29, 2025):

@enchev : HybridTestAppClient.zip

here is a zip with a minimal project that shows the exceptions being thrown. every exception that isn't handled in code shows a error message in our application, so the dispatcher errors are displayed there, but not this test app.

however, ill be digging a bit deeper into this today as well.

@joriverm commented on GitHub (Sep 29, 2025): @enchev : [HybridTestAppClient.zip](https://github.com/user-attachments/files/22591010/HybridTestAppClient.zip) here is a zip with a minimal project that shows the exceptions being thrown. every exception that isn't handled in code shows a error message in our application, so the dispatcher errors are displayed there, but not this test app. however, ill be digging a bit deeper into this today as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1875