I'm confused about what precisely the limitations are on loading plugins in
separate app domains. In all my previous apps that supported plugins, I've
loaded them into the same domain as the app, but I've just started playing
around with separate AppDomains and I'm finding that I'm not having problems
where I expected I would, so maybe someone can help me understand a bit
better.
I've read that objects instantiated in separate AppDomains need to derive
from MarshalByRefObject. Why is this?
I have an IPlugin interface. I have a class (not derived from
MarshalByRefObject) in an assembly that implements the IPlugin interface.
I've done the following to create an instance of the object (path is the
path and filename of the assembly with the class, and typeFullName is the
FullName of the Type of the object):
AppDomain domain = AppDomain.CreateDomain("PluginTest");
Assembly asm = domain.Load(path);
IPlugin plugin = asm.CreateInstance(typeFullName) as IPlugin;
The object appears to instantiate fine and I called two different
properties, one that returned a string and one that returned a Guid. Both
returned the correct objects.
So I'm confused. Why do I need to derive from MarshalByRefObject?
Or have I done something wrong that somehow created the object in my primary
AppDomain?
I'm not really sure I need the separate AppDomain stuff for what I'm doing,
but thought I'd play with it while I'm creating this new plugin manager to
see what all the fuss is about.
Pete 6 4473
Whe you store the plugin objects in your main AppDomain, then you've
defeated the purpose of beeing able to completly unload your plugins.
In order for the plugin assemblies only to be loaded in the second AppDomain
you must be sure that your primary AppDomain never obtains a direct
reference to a method/class/type/etc. from one of those assemblies.... you
must remote the call. This means you need a ("remote") object reference, a
class that is derieved from MarshalByRef-Object".
You loaded the Assemblies locally ;)
Hope that makes things clearer,
Markus
"Pete Davis" <pdavis68@[nospam]hotmail.com> schrieb im Newsbeitrag
news:bI********************@giganews.com... I'm confused about what precisely the limitations are on loading plugins in separate app domains. In all my previous apps that supported plugins, I've loaded them into the same domain as the app, but I've just started playing around with separate AppDomains and I'm finding that I'm not having problems where I expected I would, so maybe someone can help me understand a bit better.
I've read that objects instantiated in separate AppDomains need to derive from MarshalByRefObject. Why is this?
I have an IPlugin interface. I have a class (not derived from MarshalByRefObject) in an assembly that implements the IPlugin interface. I've done the following to create an instance of the object (path is the path and filename of the assembly with the class, and typeFullName is the FullName of the Type of the object):
AppDomain domain = AppDomain.CreateDomain("PluginTest"); Assembly asm = domain.Load(path); IPlugin plugin = asm.CreateInstance(typeFullName) as IPlugin;
The object appears to instantiate fine and I called two different properties, one that returned a string and one that returned a Guid. Both returned the correct objects.
So I'm confused. Why do I need to derive from MarshalByRefObject?
Or have I done something wrong that somehow created the object in my primary AppDomain?
I'm not really sure I need the separate AppDomain stuff for what I'm doing, but thought I'd play with it while I'm creating this new plugin manager to see what all the fuss is about.
Pete
Markus,
Thanks. I suspected that I had to be doing something wrong and that I was
somehow loading the assembly locally, because I just couldn't believe it
would be that simple.
But I'm curious, the attempt to unload the AppDomain appears to work. I say
"appears" to work, in the sense that it doesn't fail. So am I to understand
the AppDomain unloaded, but the assembly itself simpy, under the hood, moved
into my local domain without any sort of notification or warning? That seems
awefully strange to me.
Pete
"Markus Kling" <ma**********@nospam.nospam> wrote in message
news:Oo**************@TK2MSFTNGP14.phx.gbl... Whe you store the plugin objects in your main AppDomain, then you've defeated the purpose of beeing able to completly unload your plugins. In order for the plugin assemblies only to be loaded in the second AppDomain you must be sure that your primary AppDomain never obtains a direct reference to a method/class/type/etc. from one of those assemblies.... you must remote the call. This means you need a ("remote") object reference, a class that is derieved from MarshalByRef-Object". You loaded the Assemblies locally ;) Hope that makes things clearer,
Markus
"Pete Davis" <pdavis68@[nospam]hotmail.com> schrieb im Newsbeitrag news:bI********************@giganews.com... I'm confused about what precisely the limitations are on loading plugins in separate app domains. In all my previous apps that supported plugins, I've loaded them into the same domain as the app, but I've just started playing around with separate AppDomains and I'm finding that I'm not having problems where I expected I would, so maybe someone can help me understand a bit better.
I've read that objects instantiated in separate AppDomains need to derive from MarshalByRefObject. Why is this?
I have an IPlugin interface. I have a class (not derived from MarshalByRefObject) in an assembly that implements the IPlugin interface. I've done the following to create an instance of the object (path is the path and filename of the assembly with the class, and typeFullName is the FullName of the Type of the object):
AppDomain domain = AppDomain.CreateDomain("PluginTest"); Assembly asm = domain.Load(path); IPlugin plugin = asm.CreateInstance(typeFullName) as IPlugin;
The object appears to instantiate fine and I called two different properties, one that returned a string and one that returned a Guid. Both returned the correct objects.
So I'm confused. Why do I need to derive from MarshalByRefObject?
Or have I done something wrong that somehow created the object in my primary AppDomain?
I'm not really sure I need the separate AppDomain stuff for what I'm doing, but thought I'd play with it while I'm creating this new plugin manager to see what all the fuss is about.
Pete
What I wrote was not (!) totally correct but ment to illustrate the
scenario. To be me more clear:
Code running in one application cannot directly access code or resources
from another application. The common language runtime enforces this
isolation by preventing direct calls between objects in different
application domains. Objects that pass between domains are either copied or
accessed by proxy. If the object is copied, the call to the object is local.
That is, both the caller and the object being referenced are in the same
application domain. If the object is accessed through a proxy, the call to
the object is remote. In this case, the caller and the object being
referenced are in different application domains.
You did the first thing. Copying requires the classes to be loaded ;)
Markus Markus,
Thanks. I suspected that I had to be doing something wrong and that I was somehow loading the assembly locally, because I just couldn't believe it would be that simple.
But I'm curious, the attempt to unload the AppDomain appears to work. I say "appears" to work, in the sense that it doesn't fail. So am I to understand the AppDomain unloaded, but the assembly itself simpy, under the hood, moved into my local domain without any sort of notification or warning? That seems awefully strange to me.
Pete
"Markus Kling" <ma**********@nospam.nospam> wrote in message news:Oo**************@TK2MSFTNGP14.phx.gbl... Whe you store the plugin objects in your main AppDomain, then you've defeated the purpose of beeing able to completly unload your plugins. In order for the plugin assemblies only to be loaded in the second AppDomain you must be sure that your primary AppDomain never obtains a direct reference to a method/class/type/etc. from one of those assemblies.... you must remote the call. This means you need a ("remote") object reference, a class that is derieved from MarshalByRef-Object". You loaded the Assemblies locally ;) Hope that makes things clearer,
Markus
"Pete Davis" <pdavis68@[nospam]hotmail.com> schrieb im Newsbeitrag news:bI********************@giganews.com... I'm confused about what precisely the limitations are on loading plugins in separate app domains. In all my previous apps that supported plugins, I've loaded them into the same domain as the app, but I've just started playing around with separate AppDomains and I'm finding that I'm not having problems where I expected I would, so maybe someone can help me understand a bit better.
I've read that objects instantiated in separate AppDomains need to derive from MarshalByRefObject. Why is this?
I have an IPlugin interface. I have a class (not derived from MarshalByRefObject) in an assembly that implements the IPlugin interface. I've done the following to create an instance of the object (path is the path and filename of the assembly with the class, and typeFullName is the FullName of the Type of the object):
AppDomain domain = AppDomain.CreateDomain("PluginTest"); Assembly asm = domain.Load(path); IPlugin plugin = asm.CreateInstance(typeFullName) as IPlugin;
The object appears to instantiate fine and I called two different properties, one that returned a string and one that returned a Guid. Both returned the correct objects.
So I'm confused. Why do I need to derive from MarshalByRefObject?
Or have I done something wrong that somehow created the object in my primary AppDomain?
I'm not really sure I need the separate AppDomain stuff for what I'm doing, but thought I'd play with it while I'm creating this new plugin manager to see what all the fuss is about.
Pete
Okay, now I'm confused again:
1: Did the assembly load into the primary app domain or the secondary
appdomain that I created?
2: If the object copies to my primary appdomain but the assembly is still
loaded into the secondary appdomain, what happens when I unload the
secondary app domain if I have removed all references to the objects that
were "copied" over? What happens if I don't remove the references?
If the object is copied into my app domain, but the secondary AppDomain and
assembly in it can be unloaded, that would more or less accomplish my
requirements. I suspect this isn't the case, though. Too simple.
Pete
"Markus Kling" <ma**********@nospam.nospam> wrote in message
news:O5**************@TK2MSFTNGP12.phx.gbl... What I wrote was not (!) totally correct but ment to illustrate the scenario. To be me more clear:
Code running in one application cannot directly access code or resources from another application. The common language runtime enforces this isolation by preventing direct calls between objects in different application domains. Objects that pass between domains are either copied or accessed by proxy. If the object is copied, the call to the object is local. That is, both the caller and the object being referenced are in the same application domain. If the object is accessed through a proxy, the call to the object is remote. In this case, the caller and the object being referenced are in different application domains.
You did the first thing. Copying requires the classes to be loaded ;)
Markus
Markus,
Thanks. I suspected that I had to be doing something wrong and that I was somehow loading the assembly locally, because I just couldn't believe it would be that simple.
But I'm curious, the attempt to unload the AppDomain appears to work. I say "appears" to work, in the sense that it doesn't fail. So am I to understand the AppDomain unloaded, but the assembly itself simpy, under the hood, moved into my local domain without any sort of notification or warning? That seems awefully strange to me.
Pete
"Markus Kling" <ma**********@nospam.nospam> wrote in message news:Oo**************@TK2MSFTNGP14.phx.gbl... Whe you store the plugin objects in your main AppDomain, then you've defeated the purpose of beeing able to completly unload your plugins. In order for the plugin assemblies only to be loaded in the second AppDomain you must be sure that your primary AppDomain never obtains a direct reference to a method/class/type/etc. from one of those assemblies.... you must remote the call. This means you need a ("remote") object reference, a class that is derieved from MarshalByRef-Object". You loaded the Assemblies locally ;) Hope that makes things clearer,
Markus
"Pete Davis" <pdavis68@[nospam]hotmail.com> schrieb im Newsbeitrag news:bI********************@giganews.com... I'm confused about what precisely the limitations are on loading plugins in separate app domains. In all my previous apps that supported plugins, I've loaded them into the same domain as the app, but I've just started playing around with separate AppDomains and I'm finding that I'm not having problems where I expected I would, so maybe someone can help me understand a bit better.
I've read that objects instantiated in separate AppDomains need to derive from MarshalByRefObject. Why is this?
I have an IPlugin interface. I have a class (not derived from MarshalByRefObject) in an assembly that implements the IPlugin interface. I've done the following to create an instance of the object (path is the path and filename of the assembly with the class, and typeFullName is the FullName of the Type of the object):
AppDomain domain = AppDomain.CreateDomain("PluginTest"); Assembly asm = domain.Load(path); IPlugin plugin = asm.CreateInstance(typeFullName) as IPlugin;
The object appears to instantiate fine and I called two different properties, one that returned a string and one that returned a Guid. Both returned the correct objects.
So I'm confused. Why do I need to derive from MarshalByRefObject?
Or have I done something wrong that somehow created the object in my primary AppDomain?
I'm not really sure I need the separate AppDomain stuff for what I'm doing, but thought I'd play with it while I'm creating this new plugin manager to see what all the fuss is about.
Pete
Hi Pete,
the common language runtime allows multiple applications to be run in a
single operating system process by using a construct called an application
domain to isolate those applications from one another. In many respects,
application domains are the CLR's equivalent of an operating system process 1: Did the assembly load into the primary app domain or the secondary appdomain that I created?
Application domains are the smalest unit of code-loading and -unloading in
the CLR. The user code is isolated to the domain in which it is loaded. That
is, the code cannot be directly called from outside the containing
application domain, nor can it make direct calls to code loaded in other
domains.
If a single assembly is used by several applications in the same process,
the CLR will load multiple copies of it by default-one for each domain in
which the assembly is used. This is necessary since each application domain
that accesses the assembly must have a separate copy of the static data or
method to prevent references to objects in static variables from crossing
domain boundaries.
Unload can be useed to free the resources associated with a particular
domain and result in a graceful shutdown. That is, each thread running in
the domain is sent a ThreadAbort exception, then unwound to the domain
boundary, no new threads are allowed to enter the domain, and all
domain-specific data structures are then freed (the copy of the static
variables and the related CLR data structures).
2: If the object copies to my primary appdomain but the assembly is still loaded into the secondary appdomain, what happens when I unload the secondary app domain if I have removed all references to the objects that were "copied" over? What happens if I don't remove the references?
Since it is a "non-domain" natural library in both cases the assembly stays
loaded. In the second case the objects can even not be garbadge collected
until the last thread dies.
For further reading start at http://msdn.microsoft.com/netframework/ecma/
Hope that helps you understand.
Markus
awisto business solutions GmbH
PS To be corrent: there is NO mechanism to "fully" unload (release all
associated memory) even a domain-neutral assembly other than shutting down
the process or completely unloading the CLR
"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:T6********************@giganews.com... Okay, now I'm confused again:
1: Did the assembly load into the primary app domain or the secondary appdomain that I created?
Domain.Load(assembly) loads the assembly in both, the target AD and the
current AD.
2: If the object copies to my primary appdomain but the assembly is still loaded into the secondary appdomain, what happens when I unload the secondary app domain if I have removed all references to the objects that were "copied" over? What happens if I don't remove the references?
When unloading the secondary AD, the assembly is unloaded from this AD, but
stays loaded in the current (default) AD.
If the object is copied into my app domain, but the secondary AppDomain and assembly in it can be unloaded, that would more or less accomplish my requirements. I suspect this isn't the case, though. Too simple.
The instance of the Type you created with CreateInstance is created in the
current AD, not in the secondary domain.
Please read the documentation on Domain.Load very carefully, and add some
code that shows you where your assembly gets loaded and where your type gets
instanciated, basically AppDomain.Load is used to load an assembly in the
current AD, this is not what you are after isn't it?.
Pete
"Markus Kling" <ma**********@nospam.nospam> wrote in message news:O5**************@TK2MSFTNGP12.phx.gbl... What I wrote was not (!) totally correct but ment to illustrate the scenario. To be me more clear:
Code running in one application cannot directly access code or resources from another application. The common language runtime enforces this isolation by preventing direct calls between objects in different application domains. Objects that pass between domains are either copied or accessed by proxy. If the object is copied, the call to the object is local. That is, both the caller and the object being referenced are in the same application domain. If the object is accessed through a proxy, the call to the object is remote. In this case, the caller and the object being referenced are in different application domains.
You did the first thing. Copying requires the classes to be loaded ;)
Markus
Markus,
Thanks. I suspected that I had to be doing something wrong and that I was somehow loading the assembly locally, because I just couldn't believe it would be that simple.
But I'm curious, the attempt to unload the AppDomain appears to work. I say "appears" to work, in the sense that it doesn't fail. So am I to understand the AppDomain unloaded, but the assembly itself simpy, under the hood, moved into my local domain without any sort of notification or warning? That seems awefully strange to me.
Pete
"Markus Kling" <ma**********@nospam.nospam> wrote in message news:Oo**************@TK2MSFTNGP14.phx.gbl... Whe you store the plugin objects in your main AppDomain, then you've defeated the purpose of beeing able to completly unload your plugins. In order for the plugin assemblies only to be loaded in the second AppDomain you must be sure that your primary AppDomain never obtains a direct reference to a method/class/type/etc. from one of those assemblies.... you must remote the call. This means you need a ("remote") object reference, a class that is derieved from MarshalByRef-Object". You loaded the Assemblies locally ;) Hope that makes things clearer,
Markus
"Pete Davis" <pdavis68@[nospam]hotmail.com> schrieb im Newsbeitrag news:bI********************@giganews.com... > I'm confused about what precisely the limitations are on loading > plugins in separate app domains. In all my previous apps that > supported plugins, I've loaded them into the same domain as the app, > but I've just started playing around with separate AppDomains and I'm > finding that I'm not having problems where I expected I would, so > maybe someone can help me understand a bit better. > > I've read that objects instantiated in separate AppDomains need to > derive from MarshalByRefObject. Why is this? > > I have an IPlugin interface. I have a class (not derived from > MarshalByRefObject) in an assembly that implements the IPlugin > interface. I've done the following to create an instance of the object > (path is the path and filename of the assembly with the class, and > typeFullName is the FullName of the Type of the object): > > AppDomain domain = AppDomain.CreateDomain("PluginTest"); > Assembly asm = domain.Load(path); > IPlugin plugin = asm.CreateInstance(typeFullName) as IPlugin; > > The object appears to instantiate fine and I called two different > properties, one that returned a string and one that returned a Guid. > Both returned the correct objects. > > So I'm confused. Why do I need to derive from MarshalByRefObject? > > Or have I done something wrong that somehow created the object in my > primary AppDomain? > > I'm not really sure I need the separate AppDomain stuff for what I'm > doing, but thought I'd play with it while I'm creating this new plugin > manager to see what all the fuss is about. > > Pete > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: stu_pb |
last post by:
I am designing a plugin system for a window application using .NET(C#
specifically). One of the requirements of the plugin system is to be able to
dynamically load/unload plugins.
My initial...
|
by: Christoph Haas |
last post by:
Dear coders...
I'm working on an application that is supposed to support "plugins".
The idea is to use the plugins as packages like this:
Plugins/
__init__.py
Plugin1.py
Plugin2.py...
|
by: nickdu |
last post by:
I'm trying to isolate "applications" into their own application domain within
a single process. I've quoted applications because it's a logical
representation of an application. Basically it...
|
by: Mike Krueger |
last post by:
Hi
I'm currently working on a forms designer for a free .NET IDE
(SharpDevelop -> www.icsharpcode.net/OpenSource/SD).
problem:
I try to put 'custom' components (user controls from the current...
|
by: ASayre |
last post by:
I'm currently developing a client that connects to a server and exchanges
data with the server back and forth. The client retains the data in specified
classes depending on what was received. While...
|
by: Oenone |
last post by:
I have created a number of "plug-in" DLLs for my ASP.NET application which
are dynamically loaded at run-time. This is done by locating the DLL file on
disk and loading it using the...
|
by: ZaX |
last post by:
Good day folks,
I'm working with a third-party transactionnal SDK, packaged into a few DLL.
In a particular scenario, I need to have two sessions opened on the
infrastructure I access thru the...
|
by: dandorey1 |
last post by:
I'm currently in the process of writing a realtime telephony
application. I've designed it with a fairly simply plugin architecture.
When I first started reading about this the general suggestion...
|
by: npthomson |
last post by:
Hi all,
This could get a bit complicated but I'll try to be as clear as
possible. I've written an application that discovers plugins at
runtime using reflection from a subdirectory of the...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |