using Assembly.Load / Statics / Singelton-Objects

P

Peter

Hi

I can create types from dynamic loaaded assemblies (Assembly.Load)
with Assembly.GetTyp( <typename> ) - OK
I need a reference to the assembly (just Type.GetType() do not work )

now my question.

1) If i need different Types/Objects of the same Assembly in different
app.sections, should I use Assembly.Load() several times or shoud I
manage all dynamic loaded assemblies by myself (e.g. Hashtable) or is
there .net functionality to do this ?

2) How should I handle static / singelton-Objects in dynamic loaded
assemblies. Can other dyn-loaded types access them? What happens with
static / singelton-Objects loading the same Assembly again ?

Thank you
Peter
 
M

Mattias Sjögren

1) If i need different Types/Objects of the same Assembly in different
app.sections, should I use Assembly.Load() several times or shoud I
manage all dynamic loaded assemblies by myself (e.g. Hashtable) or is
there .net functionality to do this ?

If you Load the same assembly more than once, the exsting copy will be
used. So you'll not get multiple instances of the same assembly in the
same appdomain.

2) How should I handle static / singelton-Objects in dynamic loaded
assemblies. Can other dyn-loaded types access them? What happens with
static / singelton-Objects loading the same Assembly again ?

Again, the existing copy is used. So they will share all statics and
singletons.

If the objects can be accessed from other types depend on how you
expose them.


Mattias
 
A

Arne Vajhøj

Peter said:
I can create types from dynamic loaaded assemblies (Assembly.Load)
with Assembly.GetTyp( <typename> ) - OK
I need a reference to the assembly (just Type.GetType() do not work )

now my question.

1) If i need different Types/Objects of the same Assembly in different
app.sections, should I use Assembly.Load() several times or shoud I
manage all dynamic loaded assemblies by myself (e.g. Hashtable) or is
there .net functionality to do this ?

I would consider it most nice to save the assembly reference, but you
will not be able to load the same assembly twice (in the same app
domain).
2) How should I handle static / singelton-Objects in dynamic loaded
assemblies. Can other dyn-loaded types access them?

If they can get a ref to it - yes, but ...
What happens with
static / singelton-Objects loading the same Assembly again ?

You can not. In same app domain.

If you load them in different app domains, then it is
different classes and you will have multiple instances.

Arne
 
P

Peter

I would consider it most nice to save the assembly reference, but you
will not be able to load the same assembly twice (in the same app
domain).


If they can get a ref to it - yes, but ...


You can not. In same app domain.

If you load them in different app domains, then it is
different classes and you will have multiple instances.

Arne

Thank you.

So the "easygoing" solution is using Assembly.Load(..) whenever i
need the assembly.
( --> 1st time .net load the assembly, further calls .net give me the
reference to the loaded assembly -- in the same app domain.)


Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top