What will be the impact, if an application has unused DLL reference (framework dll) added to the project during compilation?
Like, will it increase the assembly size? will it load those DLLs at runtime? etc
This question is not about optimization. This is to better understand the .NET infrastructure.
No, the C# compiler only puts assembly references in the final assembly for assemblies that contain types that are actually used in your code. The only impact of adding unused assemblies is a very slight slowdown of the compilation itself.
You can see this for yourself with ildasm.exe. Run it on the final assembly, double-click the manifest and look for the
.assemblydirectives.This is heavily optimized at runtime as well, assemblies are loaded by the just-in-time compiler. Which only does so if you actually call a method of a type in that assembly.