470,591 Members | 1,598 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

using Assembly.Load / Statics / Singelton-Objects

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
Dec 10 '07 #1
3 2009
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 10 '07 #2
Peter wrote:
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
Dec 10 '07 #3
On 11 Dez., 00:40, Arne Vajhøj <a...@vajhoej.dkwrote:
Peter wrote:
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
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



Dec 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Marcin Vorbrodt | last post: by
3 posts views Thread by TT (Tom Tempelaere) | last post: by
3 posts views Thread by René P. | last post: by
reply views Thread by mathlec | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.