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 4346
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: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
|
by: DizelArs |
last post by:
Hi all)
Faced with a problem, element.click() event doesn't work in Safari browser.
Tried various tricks like emulating touch event through a function:
let clickEvent = new Event('click', {...
|
by: F22F35 |
last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
| |