473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Inheritance Woes

Running into an issue where the compiler will throw an error...

"The type '<BaseClass>' is defined in an assembly that is not referenced.
You must add a reference to assembly '<BaseClass>'."

.... when using a derived class where the base class and the derived class
are compiled into separate assemblies. In this case we are attempting to
reference the derived class in a project and had assumed that the base class
assembly would automatically be referenced via the derived class's assembly.

This seems to defeat the purpose of inheritance in C#! Is it at all
possible to accomplish this without having to reference both the derived and
the base class? With only one base class and a single derived class it is
not that big a deal to reference both, but the idea behind doing this is that
we could have several derived class assemblies chained together. Having to
reference the entire chain in each assembly's project .... well you get the
idea.
Thanks
Dec 12 '05 #1
5 1412
How does this defeat the purpose of inheritance? One of the main purposes is
to avoid having multiple copies of the same code all over the place. The
base class has the base class code. If you don't reference its assembly,
where do you expect it to come from? You expect the derived class to copy
it? THAT would defeat the purpose of inheritance.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"rkozlin" <rk*****@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.com...
Running into an issue where the compiler will throw an error...

"The type '<BaseClass>' is defined in an assembly that is not referenced.
You must add a reference to assembly '<BaseClass>'."

... when using a derived class where the base class and the derived class
are compiled into separate assemblies. In this case we are attempting to
reference the derived class in a project and had assumed that the base
class
assembly would automatically be referenced via the derived class's
assembly.

This seems to defeat the purpose of inheritance in C#! Is it at all
possible to accomplish this without having to reference both the derived
and
the base class? With only one base class and a single derived class it is
not that big a deal to reference both, but the idea behind doing this is
that
we could have several derived class assemblies chained together. Having
to
reference the entire chain in each assembly's project .... well you get
the
idea.
Thanks

Dec 13 '05 #2
First, how would the derived class know where to find the base class
code? The error you're complaining about is a compile-time thing, at
the very beginning of the life cycle of an assembly. If I write in one
of my assemblies:

public class Derived : HaveAGoodTimeFindingThisBaseClass
{
...
}

Where is the compiler supposed to look to find the definition for
HaveAGoodTimeFindingThisBaseClass? I mean, _I_ know where it is, but
the compiler has no idea. It may be in an adjacent folder, another
drive, or somewhere on the network. It has no idea.

I suppose that it could try looking in the GAC to see if it finds
anything by that name, but not all assemblies are stored in the GAC.

So I cannot even imagine how a derived class would "automatically"
reference its base class at compile time, unless you mean that the
compiler should scan the GAC looking for likely matches.

Besides all of this, you also have to have the base class assembly
accessible at run time: either in the same directory as the executable
(or in a few other places that .NET searches automatically) or in the
GAC. This is where Kevin's objection takes over: you need both
assemblies at run time because the compiler does _not_ copy base class
code into the derived assembly, and it does not do so for very good
reasons related to versioning.

Dec 13 '05 #3
> Running into an issue where the compiler will throw an error...

"The type '<BaseClass>' is defined in an assembly that is not
referenced. You must add a reference to assembly '<BaseClass>'."

... when using a derived class where the base class and the derived
class are compiled into separate assemblies. In this case we are
attempting to reference the derived class in a project and had assumed
that the base class assembly would automatically be referenced via the
derived class's assembly.

This seems to defeat the purpose of inheritance in C#! Is it at all
possible to accomplish this without having to reference both the
derived and the base class? With only one base class and a single
derived class it is not that big a deal to reference both, but the
idea behind doing this is that we could have several derived class
assemblies chained together. Having to reference the entire chain in
each assembly's project .... well you get the idea.

Thanks


I don't see how it defeats the purpose of inheritance. Are you sure of the
definition of inheritance?

The only way around not having to reference both DLLs into your app is to
not expose any of the base assembly's type in the public interface of the
"sub-classed" assembly.
Dec 13 '05 #4
First, let me make sure you three understand the situation. We have these
projects:

BaseClass
DerivedClass
TestApp

BaseClass references nothing nonstandard. DerivedClass references
BaseClass's assembly because it inherits from BaseClass. TestApp references
DerivedClass's assembly because it is instantiating an object from it. Not
sure if I can "gump" that any further for you.

On compile we fail because the C#.Net compiler was created in such a way as
to require BaseClass's assembly referenced on TestApp!!! Now, stop there.
Think hard fellas. If you do not see the problem here then just don't bother
responding. I can only suggest you duplicate this solution/project in VB.Net.

Why? Because I did that this morning... and guess what? It works! If C#
cannot do this then I would like it explained exactly why it cannot. I want
to know why VB can go where C# cannot.

I would like a Microsoft Rep to respond to this please.
"chris martin" wrote:
Running into an issue where the compiler will throw an error...

"The type '<BaseClass>' is defined in an assembly that is not
referenced. You must add a reference to assembly '<BaseClass>'."

... when using a derived class where the base class and the derived
class are compiled into separate assemblies. In this case we are
attempting to reference the derived class in a project and had assumed
that the base class assembly would automatically be referenced via the
derived class's assembly.

This seems to defeat the purpose of inheritance in C#! Is it at all
possible to accomplish this without having to reference both the
derived and the base class? With only one base class and a single
derived class it is not that big a deal to reference both, but the
idea behind doing this is that we could have several derived class
assemblies chained together. Having to reference the entire chain in
each assembly's project .... well you get the idea.

Thanks


I don't see how it defeats the purpose of inheritance. Are you sure of the
definition of inheritance?

The only way around not having to reference both DLLs into your app is to
not expose any of the base assembly's type in the public interface of the
"sub-classed" assembly.

Dec 13 '05 #5
I hope that works out for you. Good luck.

Dec 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mark | last post by:
O, woe is me, to have seen what I have seen, see what I see! (That's Shakespeare for those who were wondering what I'm on about) I am "having fun" with cookies. And I wonder if I have...
0
by: Cedric | last post by:
This is a 3 weeks old problem, but having found a solution (and having looked for one here, finding only this message), I'm replying now. From: Jive (someone@microsoft.com) Subject: Upgrade...
3
by: Angel Cat | last post by:
Trying to get my jobs to send mail when job fails. Should be easy but it's giving me headache Had a whole slew of issues. Outlook is installed with a n outlook mail profile set up that can...
2
by: Andrew Thompson | last post by:
- NN 4.78 rendering woes, links at far left - I am trying to rework an old site, make it valid html and css, improving the x-browser and 'older browser' compatibility. My efforts so far, have...
0
by: Arun Bhalla | last post by:
I'm having some inconsistency problems with my deployment project ("Setup") and its custom actions ("Installer"). I'm using Visual Studio .NET 2003 (.NET 1.1, no service pack) on Windows XPSP1. ...
4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
5
by: relient | last post by:
This is rediculous. It is said when you override a method in a derived class that's implemented in the base class, you "override the base class methods" implementation, correct? but in my test,...
9
by: Mark Rae | last post by:
Hi, This time, I'm looking for a regular expression which says "the string must contain exactly seven or exactly eight digits" e.g. 123456 fails 1234567 passes 12345678 passes 123456789...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.