Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay loading in c#?

Tags:

c#

Is there such a thing as delay loading a dll in C#? I know this is possible to do in C++, but what about managed code?

like image 925
Cyan Avatar asked Dec 01 '11 16:12

Cyan


2 Answers

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

like image 101
leppie Avatar answered Sep 22 '22 11:09

leppie


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.

like image 45
StayOnTarget Avatar answered Sep 25 '22 11:09

StayOnTarget