C# Visual studio needs reference to base class dll
Why do I get this problem?
Background: myClass
inherits from a class ABC
which inherits from a BaseClass
.
BaseClass开发者_运维百科
is a custom created class in a different namespace and contained in a different DLL assembly.
Issue: VisualStudio wants me to add a reference to the BaseClass
DLL - otherwise it won't compile myClass
.
- Why don't the compiler make use of the metadata?
- What if I bought the DLL (possibly without source code) and the vendor uses hundreds of classes to inherit from, why would I need to add (and know) all those references?
Thanks
How could it get the metadata for the base class if you don't provide it? It doesn't get copied from the base class to the derived class and stored in the derived class' assembly.
Your vendor scenario is just not realistic. Nobody designs class hierarchies that are a hundred classes deep, let alone store each of them in a separate assembly. This tops out at six or seven, at worst. With one base assembly, sometimes two. Any deeper and nobody can understand how it works anymore.
Regarding your vendor
scenario - you won't be forced to reference all the libraries from vendor's library if that library doesn't expose anything from other libs and all those libs are used only internally.
But if a library for example returns a class from another library (or it's inheritor) then of course you'll have to reference both. Just in order to get all the information about those exposed classes.
If BaseClass isn't referenced, how would your program know about it and its definition? Where is it supposed to grab the meta data from if it has no reference to it?
It's like asking a web server-side related question on SO but not telling anyone what language/platform you're using - there's no frame of reference.
Let's answer your questions...
In order to compile the code for MyClass, it needs to know what Class did. In order to know what Class did, it needs to see what BaseClass did - it's like a chain.
You need to include anything you are building against in your project. This can be done by either actually having the source for whatever in your project, or by including a reference to the project / binary where the behaviour is defined.
Meta data doesn't contain any details about the actual logic in a class.
精彩评论