Where is the reference to IObservable
-
27-10-2019 - |
Question
The following is not compiling on VS2010, SL5 and Reactive Extensions version 1.1.10605.1(2011-06-05).
'System.Collections.Generic.IEnumerable' does not contain a definition for 'ToObservable' and no extension method 'ToObservable' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void ButtonNormal_Click(object sender, RoutedEventArgs e)
{
//MyList.ItemsSource = GetModel();
var items = new System.Collections.ObjectModel.ObservableCollection<string>();
MyList.ItemsSource = items;
foreach (string item in GetModel())
items.Add(item);
}
private void ButtonRx_Click(object sender, RoutedEventArgs e)
{
var items = new System.Collections.ObjectModel.ObservableCollection<string>();
MyList.ItemsSource = items;
IObservable<string> observable = GetModel()
.ToObservable(System.Concurrency.Scheduler.NewThread);
observable.ObserveOnDispatcher().Subscribe(item => items.Add(item));
}
}
Solution
Try adding 'using System.Reactive.Linq' ?
OTHER TIPS
Just in case anyone is interesting this is now deprecaited and is System.Observable namespace
maybe you are not referencing/using to the reactive assembly?
did you referenced the mscorlib.dll?
Also it might be that you need to include the System.Observable.dll to your project.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow