Link to home
Start Free TrialLog in
Avatar of iangregson1
iangregson1

asked on

Adding a reference to one assembly requires additional references!

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

ASKER CERTIFIED SOLUTION
Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

Avatar of iangregson1
iangregson1

ASKER

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 :-)
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
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...