Question
It seems to me that any time I make a class library, all of its dependencies should just come with it. In other words, I would expect to just reference a .dll and go. After all, the .dll I reference builds just fine on its own.
Is this not the case? I reference all of a dependency's dependencies, in order to use it?
Looking forward to being enlightened about this.
Issue
To illustrate, here's an example.
ClassLibrary1
is a class library project, with one public class:Class1
.ClassLibrary2
is another class library, in the same solution, with one public class:Class1
.These two classes exist in their own namespaces.
However,
ClassLibrary2
referencesClassLibrary1
, andClassLibrary2.Class1
inherits fromClassLibrary1.Class1
.ConsoleApplication1
is a console app, in the same solution, that references onlyClassLibrary2
.
Up to this point, everything builds. Everything is the same framework.
However, when I attempt to initiate ClassLibrary2.Class1
, I get a build error:
Error 1 The type 'ClassLibrary1.Class1' is defined in an assembly that is not referenced. You must add a reference to assembly 'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. ...\ConsoleApplication1\Program.cs 12 4 ConsoleApplication1
Code Snippets
namespace ClassLibrary1
{
public class Class1
{
public Class1() { }
}
}
...
namespace ClassLibrary2
{
public class Class1 : ClassLibrary1.Class1
{
public Class1() : base() { }
}
}
...
namespace ConsoleApplication1
{
using ClassLibrary2;
class Program
{
static void Main(string[] args)
{
// error mentioned previously in post is on following line
var a = new Class1();
}
}
}