I have an intensive Java background so forgive me if I\'m overlooking something obvious in C#, but my research is getting me nowhere. I am trying to use the reactive Rx .NET lib
As of version 3, the Rx
project is now known as System.Reactive
because it "brings the NuGet package naming in line with NuGet guidelines and also the dominant namespace in each package."
It can be downloaded from NuGet by searching for "System.Reactive" or you can download it here: https://www.nuget.org/packages/System.Reactive/
Here is the project's GitHub page: https://github.com/Reactive-Extensions/Rx.NET
Rx-Main
System.Reactive
Rx-Core
System.Reactive.Core
Rx-Interfaces
System.Reactive.Interfaces
Rx-Linq
System.Reactive.Linq
Rx-PlatformServices
System.Reactive.PlatformServices
Rx-Testing
Microsoft.Reactive.Testing
Source
You have probably not added the necessary assembly references for Rx to your project. (Referencing an assembly is not the same thing as importing a namespace! You already know what a namespace is; an assembly is something similar to a JAR; the smallest unit of code deployment/distribution. Your project must reference it before the namespaces defined inside it become available for use.)
The compiler likely doesn't complain about IObservable<T>
and IObserver<T>
because your project is targeting .NET Framework version 4 or later. These two interfaces have been part of the core .NET Framework Class Library (FCL) since .NET version 4. (If you targeted an earlier .NET version, you'd get errors for using these undefined interfaces, too.)
Every part of Rx other than these two interfaces is not included in the core .NET FCL, but resides in their own (add-on) assemblies. You can add them to your project e.g. by installing the corresponding NuGet packages:
In Visual Studio, go to Tools → NuGet Package Manager → Package Manager Console.
In the NuGet console window, select the target project (where you want to use Rx) in the drop-down list Default project.
Next, type Install-Package System.Reactive
and hit Enter ↵. (Note: This package used to be called Rx-Main
previously; see this answer for details.)
This will add the System.Reactive.*
assembly references to your project.