Home All Groups Group Topic Archive Search About

Delayed loading dependent assemblies when start an .Net application

Author
6 Mar 2007 2:29 PM
wzhao2000
Back in COM time, it's possible to use #import statement in cpp to
load COM object type info and use it at coding time. When the
application is started, the underlying COM DLL will not be loaded
until that part of code is called.

Is there a similar thing in .Net (C#) application ?

When I create C# application, I need to add reference to another
assembly if I want to use its classes (I don't want to use reflection
here). But this will also add dependency on that assembly. The
assembly will be loaded when my application starts. Is there a way to
delay the loading of dependent assemblies only when the code using it
is called?

T.I.A.

Author
6 Mar 2007 4:17 PM
Ignacio Machin ( .NET/ C# MVP )
Hi,

<wzhao2***@gmail.com> wrote in message
Show quote
news:1173191383.442622.26430@64g2000cwx.googlegroups.com...
> Back in COM time, it's possible to use #import statement in cpp to
> load COM object type info and use it at coding time. When the
> application is started, the underlying COM DLL will not be loaded
> until that part of code is called.
>
> Is there a similar thing in .Net (C#) application ?
>
> When I create C# application, I need to add reference to another
> assembly if I want to use its classes (I don't want to use reflection
> here). But this will also add dependency on that assembly. The
> assembly will be loaded when my application starts. Is there a way to
> delay the loading of dependent assemblies only when the code using it
> is called?

You could figure out something using like a plug-in pattern, but do you
really need to delay it?

You can always delay the creation of instances until the last moment you
need it, but loading the assembly has not that much of overload to justify
delaying its load.
Author
6 Mar 2007 4:51 PM
Laura T.
The CLR will load an assembnly only when it is absolutely necessary. The
delay-loading is built in. (check
http://www.awprofessional.com/articles/article.asp?p=30601&seqNum=5&rl=1 for
a more detailed discussion of CLR loader.) You do not need to do anything
(nor you can).

By adding reference you are not forcing the assembly to be loaded at
startup.
If your code does not use any type in it, it will not get loaded.

<wzhao2***@gmail.com> ha scritto nel messaggio
Show quote
news:1173191383.442622.26430@64g2000cwx.googlegroups.com...
> Back in COM time, it's possible to use #import statement in cpp to
> load COM object type info and use it at coding time. When the
> application is started, the underlying COM DLL will not be loaded
> until that part of code is called.
>
> Is there a similar thing in .Net (C#) application ?
>
> When I create C# application, I need to add reference to another
> assembly if I want to use its classes (I don't want to use reflection
> here). But this will also add dependency on that assembly. The
> assembly will be loaded when my application starts. Is there a way to
> delay the loading of dependent assemblies only when the code using it
> is called?
>
> T.I.A.
>

AddThis Social Bookmark Button