reactiveui / reactiveui/ReactiveUI
[Bug]: WPF thread error in v24
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 8.5k
- Forks
- 1.2k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 6
Description
Describe the bug 🐞
CollectionView of this type does not support changes to its SourceCollection from threads other than the dispatcher thread.
Step to reproduce
Start WPF and trigger WhenAnyValue
public partial class MainWindow : Window, IViewFor<MainViewModel>
{
public MainViewModel? ViewModel { get; set; }
object? IViewFor.ViewModel
{
get => ViewModel;
set => ViewModel = (MainViewModel)value!;
}
public MainWindow()
{
InitializeComponent();
RxAppBuilder.CreateReactiveUIBuilder().WithWpf().BuildApp();
DataContext = ViewModel = new();
Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.Bind(ViewModel, vm => vm.Text, v => v.TextBox.Text);
this.Bind(ViewModel, vm => vm.Strings, v => v.ListBox.ItemsSource);
}
}
public class MainViewModel : ReactiveObject
{
public MainViewModel()
{
this.WhenAnyValue(x => x.Text)
.Throttle(TimeSpan.FromSeconds(1), RxSchedulers.TaskpoolScheduler)
.Where(x => string.IsNullOrWhiteSpace(x) is false)
.ObserveOn(RxSchedulers.MainThreadScheduler)
.Subscribe(x => Strings.Add(x));
}
public string Text
{
get;
set => this.RaiseAndSetIfChanged(ref field, value, nameof(Text));
}
public ObservableCollection<string> Strings { get; set; } = new();
}
Reproduction repository
https://github.com/reactiveui/ReactiveUI
Expected behavior
Strings can be used normally with the Add method.
This code can works fine in ReactiveUI v23.2.28.
Screenshots 🖼️
IDE
No response
Operating system
No response
Version
No response
Device
No response
ReactiveUI Version
24.2.0
Additional information ℹ️
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the ReactiveUI repository by tracing the WPF binding path used by Bind for ObservableCollection and the MainThreadScheduler behavior after WhenAnyValue and Throttle. Compare v24.2.0 with v23.2.28 and use the supplied WPF reproduction to identify the regression; done means Strings.Add no longer raises the dispatcher-thread CollectionView error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100