C# .NET Rx- Where is System.Reactive?

爱⌒轻易说出口 提交于 2019-12-03 01:09:30

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:

  1. In Visual Studio, go to ToolsNuGet Package ManagerPackage Manager Console.

  2. In the NuGet console window, select the target project (where you want to use Rx) in the drop-down list Default project.

  3. Next, type Install-Package System.Reactive and hit Enter ↵. (Note: This package used to be called Rx-Main previously; see this answer for details.)

  4. This will add the System.Reactive.* assembly references to your project.

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

Package Mappings

  • 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!