Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top