Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Adding a reference to one assembly requires additional references!

Posted on 2008-06-10
5
247 Views
Last Modified: 2010-04-15
Hi there,

I am trying to get straight in my head that sometimes when i add a reference to a project then it won't compile as it says that this assembly reference a,b,c,d so you must add a reference to a,b,c,d in my current project.

Confusing! :-) ... Actually i am quite used to it... and very easy to fix... just do exactly what it says...

The thing that is annoying me a little bit is that sometimes it happens and sometimes it doesn't....

Can anyone explain exactly in which scenerio it happens, is it if the other assembly exposes public methods (for example) which take parameters of another assembly.

Any ideas or help would be really appreciated...as i say its pretty easy to fix BUT i just wanted to know why ... so i can think my design up a little better..

Thanks in advance

0
Comment
Question by:iangregson1
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 500 total points
ID: 21753216
> "the other assembly exposes public methods (for example) which take parameters of another assembly."

Sounds pretty close. The assembly can also expose classes, structures, delegates, enums, etc defined by these assemblies.
0
 
LVL 14

Expert Comment

by:ajitha75
ID: 21753975
You will need to add a reference to an assembly if you are going to directly use any types(classes, structures etc) from that assembly in your project.

0
 

Author Comment

by:iangregson1
ID: 21757005
Thanks both, so to confirm, sorry still a little confused...

so if i reference an assembly and that assembly references 5 other assemblies but all the types used from these assemblies are private/internal then visual studio is not going to force me to add a reference to these 5 assemblies in my current assembly?

Is that right,

Stress, i just think i confused myself :-)
0
 
LVL 14

Expert Comment

by:ajitha75
ID: 21758382
it depends. if any of the types from those 5 assemblies are used in the public interface of your referenced assembly then it will be a problem. To give an example.

In assembly1.dll
you have a type

public class A
{
              public void method1(classB  parameter1)
              {
                         ....do something....
               }
}


Now in assembly2.dll
you have

public Class B
{
             .....methods  & properties
}

since Class B is in public interface of method1 and you are going to use method1, you will have to reference both dll.

However another scenario

In assembly1.dll
you have a type

public class A
{
              public void method1()
              {
                      B b = new B();
                         ....do something....
               }
}


Now in assembly2.dll
you have

public Class B
{
             .....methods  & properties
}


here you dont have to reference assembly2.dll
0
 

Author Comment

by:iangregson1
ID: 21759399
hi ajitha75,

yes but that isn't quite what i was referring to ...

i know if one assembly uses another it requires the reference... what i was referring to was (see my oriiginal post)....

its when an assembly reference another assembly but visual studio requires you to reference even more assemblies becasue the assembly you are referencing also references these...
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question