I recently came across a strange problem that I could not explain, and I would be glad if anyone could clarify why this is happening.
The problem I encountered is as follows:
I have an interface that is implemented, for example:
namespace InterfaceTwo { public interface IA { } } namespace InterfaceTwo { public class A : IA { } }
And one more interface, which is implemented in another project, for example:
namespace InterfaceOne { public interface IB { } } namespace InterfaceOne { public class B : IB { } }
I have an object that uses these interfaces in it constructors, for example:
using InterfaceOne; using InterfaceTwo; namespace MainObject { public class TheMainObject { public TheMainObject(IA iaObj) { } public TheMainObject(IB iaObj) { } } }
And finally, I have a class that aggregates the above object, for example:
using InterfaceTwo; using MainObject; namespace ReferenceTest { public class ReferenceTest { public void DoSomething() { var a = new A(); var theMainObject = new TheMainObject(a); } } }
Oddly enough, this code will not compile with the following error:
The type 'InterfaceOne.IB' is defined in an assembly that is not referenced.
You must add a reference to the assembly 'InterfaceOne, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null'.
c: \ users \ harry.baden \ documents \ visual studio 2013 \ Projects \ ReferenceTest \ ReferenceTest \ ReferenceTest.cs 11 13 ReferenceTest
I also found that if I changed one of the overloads to contain an additional parameter, it compiles ... Which made me think that the problem could be related to some kind of reflection problem that the compiler is working with.
Thanks,
Barak.