Delay loading in c#?

This article explains in detail how it works in .NET. Summary of key points:

There are a number of different ways that assemblies are loaded in .NET. When you create a typical project, assemblies usually come from:

  • The Assembly reference list of the top level 'executable' project

  • The Assembly references of referenced projects

  • Dynamically loaded assemblies, using runtime loading via AppDomain or Reflection loading

and

.NET automatically loads mscorlib (most of the System namespace) as part of the .NET runtime hosting process that hoists up the .NET runtime in EXE apps, or some other kind of runtime hosting environment (runtime hosting in servers like IIS, SQL Server or COM Interop).

and

  • Dependent Assembly References are not pre-loaded when an application starts (by default)

  • Dependent Assemblies that are not referenced by executing code are never loaded

  • Dependent Assemblies are just in time loaded when first referenced in code

  • Once Assemblies are loaded they can never be unloaded, unless the AppDomain that hosts them is unloaded.


.NET does that automatically, everything is loaded on demand by default.

Tags:

C#