UniRx: Extension method in UniRx.ObservableExtensions conflict with System.Reactive

In Unity 2021.2.12 (and also happening on 2022.1.0b8), the extension methods in ObservableExtensions are conflicting with the extension methods pulled in by System.Reactive.

Various error messages along the lines of: The call is ambiguous between the following methods or properties: 'UniRx.ObservableExtensions.Subscribe<T>(System.IObservable<T>)' and 'System.ObservableExtensions.Subscribe<T>(System.IObservable<T>)' are now appearing whenever there is the using UniRx; using System; appearing in the same file.

Is there a suggested workaround / solution to this issue?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 24
  • Comments: 42 (1 by maintainers)

Most upvoted comments

It’s fixed internally on Unity’s trunk and is awaiting backport to the 2021.3 branch. I requested an update earlier today on when the backport will be happening.

2021.3.0f1 is out - but this issue is still not fixed. @Nezz: Any news from your source?

I’ve just checked with 2021.3.1f1, it’s still not fixed!

The PR for the backport was submitted yesterday for 2021.3. If all goes well, it should be merged and released fairly quickly.

Still not fixed in 2021.2.19f1.

Oooh now the page says:

Fixed in: 2021.3.3f1 Fixed in: ​​​​​​​2022.1.1f1

😃

Some news:

The devs have decided to explicitly exclude System.Reactive.* assemblies from our .NET 4.8 profile. The pull request for this change is now awaiting approval.

In the meantime, it appears you can work around the problem by additionally targeting a runtime platform for the affected assembly definitions (e.g. Editor AND Stadia, if you’re not deploying on the Stadia platform, this should have no effect on the project).

A quick workaround of this issue would be put using UniRx into namespace.

namespace Game
{
    using UniRx;
    ...
}

For those code without namespace you have to remove using System as @peterdijkstra suggested.

2021.3.2, it’s still not fixed!

I opened a ticket with Unity about this.

A quick workaround of this issue would be put using UniRx into namespace.

namespace Game
{
    using UniRx;
    ...
}

For those code without namespace you have to remove using System as @peterdijkstra suggested.

This works. If you happen to be using using System; as well, put it outside of the namespace, then you can use it as normal:

using System;

namespace SomeNamaspace {
    using UniRx;

    ...
}

I’ve tried on Unity 2021.2.13f1. API Compatibillity Level: .NET Standard 2.1 is worked. API Compatibillity Level: .NET Framework, conflicts.

Indeed, it implicitly refers to System.Reactive.*.dll. I think it’s a bug in Unity, so until there’s an official announcement (references added, etc.), I’ll wait and see.

@kLy: The issue mentions, that it will be fixed in 2021.3:

Fixed in 2022.2.X Fix In Review for 2021.3.X, 2022.1.X

This issue was mentioned in Unity 2022.2a release notes.

It’s still the same in 2021.2.18f1.

I’ve just checked out 2021.2.17f1. This issue is still in this version.

Still broken in 2021.2.15f1, keep staying in 2021.2.11f1

This is the latest I got:

The devs have informed me that this looks like unintended behaviour but they will need to investigate the problem further.

It’s an enterprise support ticket, no point in linking it 😃

Woohoo! 2021.3.3 just released! https://unity3d.com/unity/whats-new/2021.3.3

And it includes the fix:

  • Scripting: Removed outdated System.Reactive extensions from .Net 4.8 profile. (1407597)

Tested on my project. Working! 😄

my unity editor version is 2022.1.0b16,when i switch to il2cpp + .net standard2.1(pc platform), this compilation error disappears

A really preliminary test on 2022.1.1f seems to show that it’s fixed. I’m just going to assume that it now works and close this issue

I have removed all using System; lines in files where this broke, and just changed IDisposable to System.IDisposable etc. That also works, but might be a hassle if you use UniRx a ton

For what it’s worth, this wasn’t a problem with 2021.2.8