I created an extension method Class1.GetChild<T>() where T : DependencyObjectin the assembly of lib1.dll. After that, all the builds depending on lib1.dll did not compile with an error:
The type "System.Windows.DependencyObject" is defined in the corresponding which is not referenced. You must add a link to the assembly "WindowsBase", etc.
Why do dependent assemblies require WindowsBase, even if they are not using GetChild?
.
Playback (vs2010.net4):
lib1.dll (links to WindowsBase)
namespace lib1
{
public static class Class1
{
public static T GetChild<T>(this DependencyObject src) where T : DependencyObject
{
return default(T);
}
}
public static class Class2
{
public static int SomeExtMethod(this string src)
{
return 0;
}
}
}
lib2.dll (links lib1 but not WindowsBase)
using lib1;
class someClass
{
void someFct()
{
"foo".SomeExtMethod();
}
}
.
Update:
I think something is definitely when mixing common methods and extension methods. I tried to demonstrate the problem in the following example:
namespace lib0
{
public class Class0 { }
}
using lib0;
namespace lib1
{
public static class Class1
{
public static void methodA<T>() where T : Class0 { }
public static void methodB(Class0 e) { }
public static void methodC(this int src) { }
}
public static class Class2
{
public static void methodD(this String s) { }
}
}
using lib1;
class someClass
{
void someFct()
{
Class2.methodD("");
"".methodD();
}
}
A, //B, //C → compile ok
A, B, //C → compile ok
//A, B, C → compile ok
A, //B, C → boost error
A, B, C → boost error
//A , methodA . , . .