views:

136

answers:

2

Just like Carl's question over here I would like to ask you (because I couldn't find it out on my own :( ) if there is any benefit by removing an assembly reference that is not statically nor dynamically (via reflection for example) used.

+5  A: 

Removing unused assembly references wouldn't change anything apart from cleaning your projects. When you add assembly references the compiler will ignore any assembly which you have not actually made use of in your code. Thus, if you were to set a reference to System.Data.dll and System.Windows.Forms.dll but only authored the following code:

using System;

public class MyClass
{
  public static void Main()
  {
    Console.WriteLine("Hi there.");
  }
}

the compiler would only reference the mandatory mscorlib.dll

Darin Dimitrov
Both your and casperOne's answers are completely fullfiling but I had to choose only one so I chose by posting time.
Andrei Rinea
... and +1 for both of you
Andrei Rinea
While this answer may be correct, the information about the `using` directives is extraneous. Namespaces and using directives have *nothing* to do with assembly references (except by convention). Everything in this answer about the 'using' directive should be removed as it confuses the issue.
Michael Burr
Well great, Michael Burr, as I agree I can't edit the man's post because my current reputation level does not allow me to edit other people's post (I think it requires 2000 points and I only got 581 right now). So... maybe someone else can do what you ask for but certainly not me :(
Andrei Rinea
Edited my post as suggested by Michael
Darin Dimitrov
+2  A: 

If you use the type dynamically, then you aren't going to have a reference in the metadata to the assembly it is contained in unless that assembly is used elsewhere in your assembly.

That being said, if you remove the reference when it is not being used, it's kind of pointless, since I believe the C# compiler will not write assembly references into the metadata of the output assembly when it's not referenced in your code anywhere.

Basically, it does it for you.

casperOne
Both your and darin's answers are completely fullfiling but I had to choose only one so I chose by posting time.
Andrei Rinea
... and +1 for both of you
Andrei Rinea