Given these interfaces and classes
public interface IFoo { }
public interface IFooWrapper<I> where I : IFoo { }
public class Foo : IFoo { }
public class FooWrapper : IFooWrapper<Foo> { }
Why does this fail?
IFooWrapper<IFoo> foo = new FooWrapper();
I know I could use dynamic
, here, but the real question is : I have a method that would receive an implementation of these interfaces, and it fails for the same reason :
Severity Code Description Project File Line Suppression State Error CS0266 Cannot implicitly convert type 'FooWrapper' to 'IFooWrapper'. An explicit conversion exists (are you missing a cast?)
The method signature would look like
void Register(IFooWrapper<IFoo> foo)
{
}
The compiler fails at the line
Register(new FooWrapper());