IObservable ambiguous reference error
Asked Answered
T

2

6

I'm using Reactive extensions in my WPF application. And while using it I'm getting below ambiguous reference error.

The type 'System.IObservable<T>' exists in both 'mscorlib.dll' and 'System.Reactive.dll'

I tried with fully qualified name also and tried this url as well, but didn't get any luck. I'm using .NET 4.0 version of Reactive Extensions.

My Code:

using System; // mscorlib.dll
using Rx = System.Reactive;

public Rx.IObservable<int> BytesReceived { get { return _bytesReceivedSubj; } } // Not valid as IObservable is in System namespace of System.Reactive.

public IObservable<int> BytesReceived { get { return _bytesReceivedSubj; } } // With this I'm getting ambiguous reference error

enter image description here

Any idea how can i resolve this?

Thanks

Tubbs answered 29/7, 2013 at 15:50 Comment(4)
The error is pretty self-explanatory. You have 2 libraries that both have a definition of IObservable so you have to clarify which one you are trying to use.Offset
Both are in "System" namespace, and in the same form I'm using System from mscorlib also for EventHandlers and all. So how I can give fully qualified name here for IObservable? If I used System.IObservable then it will again give me ambiguous reference error.Tubbs
You don't have an extra using System.Reactive; in there somewhere do you?Offset
@Kevin, No I don't have extra System.Reactive declaration in my form.Tubbs
C
5

When you reference IObservable, either use

System.Reactive.IObservable<T>

or

System.IObservable<T>

UPDATE>>>

Ahhhh, now that you've added the image, I see your problem. You have two System.IObservable classes... what idiots those Reactive guys are!

Anyway, take a look at these posts:

How to access a type with same fully qualified name in 2 different DLLs

Extern alias walkthrough

It's not pretty, but it should help you.

Cranial answered 29/7, 2013 at 16:10 Comment(1)
That's not the reason ... he must be referencing the wrong versions after upgrading or something. @JimWooley is right. Calling people idiots, especially when they aren't, is inappropriate.Tertiary
F
8

When you say you are using the .Net 4 version of Rx, which version of Rx are you using? 1.1 or 2.x? If using 2.x, you shouldn't have a reference to System.Reactive, but rather System.Reactive.Core. I suspect you upgraded this project from .Net 3.5 but didn't update all of your necessary references. Make sure the version of Rx you are using isn't for Silverlight 4 or .Net 3.5 (which didn't have IObservable/IObserver in the core).

It may be easiest if you just remove the references to reactive and have nuget re-add them for you using the Reactive Extensions - WPF Helpers version. Note: You may need to change your imports for classes using Rx to import System.Reactive.Linq if you are using the older version that had the extension methods in the older System.Linq namespace.

Facsimile answered 29/7, 2013 at 17:45 Comment(0)
C
5

When you reference IObservable, either use

System.Reactive.IObservable<T>

or

System.IObservable<T>

UPDATE>>>

Ahhhh, now that you've added the image, I see your problem. You have two System.IObservable classes... what idiots those Reactive guys are!

Anyway, take a look at these posts:

How to access a type with same fully qualified name in 2 different DLLs

Extern alias walkthrough

It's not pretty, but it should help you.

Cranial answered 29/7, 2013 at 16:10 Comment(1)
That's not the reason ... he must be referencing the wrong versions after upgrading or something. @JimWooley is right. Calling people idiots, especially when they aren't, is inappropriate.Tertiary

© 2022 - 2024 — McMap. All rights reserved.