简体   繁体   中英

Framework .NET. Difference between lot of Dll and one Exe only

I'm building a WinForms application. I would like to know if there are difference between one only .exe file or multiple Dll. Actually i have 7Mb of one .exe, and i fear of some performance issue; but i've read the Framework loads all needed Dll at startup, so the assembly fragmetation is useless. Is right?

but i've read the Framework loads all needed Dll at startup

It loads them as it finds it needs them ; this tends to mean that many are neded at startup, but there is no magic "find everything I will ever need and load it now" step. In particular, assemblies are usually loaded when JIT finds a type reference in a dll that isn't currently loaded.

Note, however, that in many ways a single large assembly is not problematic - JIT is per-type; it doesn't look at every type in the assembly when it loads it. As the same time, though - while assembly resolution / verification / fusion can get noticeable if you have too many dlls, that is only going to matter for very large numbers; a handful or a dozen or so isn't going to matter much (indeed, the .NET framework itself is split into many separate dlls).

In most scenarios, any startup performance relates mainly to the things your code does at startup - any processing of external configuration, etc. The choice of 1 assembly vs 5 (or whatever) is rarely going to be a critical factor.

For info, a quick winform test shows that any winforms usage is going to involve at least 6 dlls - most likely more (as you add features, etc):

{your application}
mscorlib
System.Windows.Forms
System
System.Drawing
Accessibility

via:

using System;
using System.Windows.Forms;
public class Program {
    static void Main() {
        Application.EnableVisualStyles();
        using (var form = new Form()) {
            Application.Run(form);
        }
        foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            Console.WriteLine(assembly.GetName().Name);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM