Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the costs of unused assembly references?

I was wondering what the various costs of referencing assemblies in a .NET solution are. I'm interested in both technical and organizational costs.

Some examples:

  • The unused Assembly contains additional bytes to ship (longer downloads, wasted space)
  • The unused Assembly might contain an exploitable security hole
  • The unused Assembly might incur additional startup costs
  • The unused Assembly might incur additional review costs (like this question)
  • The unused Assembly might confuse a new developer
like image 568
David Schmitt Avatar asked Nov 12 '10 08:11

David Schmitt


People also ask

Does removing unused references improve performance?

By removing any unused references in your application, you are preventing the CLR from loading the unused referenced modules at runtime. Which means that you will reduce the startup time of your application, because it takes time to load each module and avoids having the compiler load metadata that will never be used.

How do I remove unused from Visual Studio 2022?

Navigate to Tools > Options > Text Editor > Code Cleanup. Add a check in the "Run Code Cleanup profile on Save." Be sure to select the appropriate profile you want to execute automatically whenever you save!

How do I remove unused Nuget?

Instead of opening the Nuget Packagemanager and uninstalling things manually there is faster way: right click on the project in the Solution Explorer and go into R# Refactor menu. There you'll find the Remove unused references menu item.


2 Answers

If you reference an assembly in a project but actually don't use any types in that assembly the unused assembly will not be part of your final product. The reference is removed at compile time.

The only "overhead" of referencing unused assemblies is during development where referencing many unused assemblies may confuse the developer about what dependencies the project has. Each new assembly in your project will also create some overhead for IntelliSense and the compiler but in most cases you wont notice.

ReSharper has a function to analyze if a referenced assembly is unused.

like image 144
Martin Liversage Avatar answered Sep 20 '22 17:09

Martin Liversage


In my opinion the organizational overhead for me (and my co-workers) to even think about unused references (why do we need XML here?) is enough motivation to remove them. Consequently, I have never considered the impact on deployment or performance.

like image 23
Marijn Avatar answered Sep 22 '22 17:09

Marijn