Search code examples
wpfsystem.reactivemscorlib

IObservable ambiguous reference error


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


Solution

  • 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.