473,695 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Plugins and AppDomain(s) - One or many?

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 thought was to use System.Reflecti on.Assembly.Loa d to load the
plugins dynamically. This worked great, but I was left with no way to
dynamically unload the plugin.

So now I come to creating a new AppDomain for the plugins to reside in,
since the AppDomain can be unloaded. The problem I see with this is that
when I dynamically unload one plugin, the rest will have to be reloaded and
any data will be lost. Is that true? I could notify the plugin when it is
going to be unloaded and it could persist itself, or I could persist each
plugin automatically I suppose.

So I thought I could have an AppDomain for each plugin. Is this feasible?
Would this take up too many resources? Also in this case I would have to
have one instance of the assembly loader for each plugin since the assembly
should be loaded from inside the current application domain.

I guess I am just looking for some opinions as to which approach is the
best, easiest or hopefully both!

Thanks for your help!
Jul 21 '05 #1
4 4199
Using appdomains to isolate plugins is essentially using remoting. My
approach has been to use a single appdomain for all plugins wherever
possible and only use separate appdomains when needed. The side effect of
this grouping is that all plugins in the same appdomain will get unloaded at
the same time. You could put each plugin into a separate appdomain but this
creates its own set of problems - each plugin is now remoted to all other
objects in other appdomains. When using separate appdomains you will need to
deal with issues related to assembly probing and versioning, resolving
references to other assemblies, ensuring that versioning differences in
common/shared assemblies are dealt with, etc.

If you are still in the design phase then you could add
serialize/deserialize methods to the plugin API to aid in preserving the
state. However, this assumes that a plugin is not in the middle of an
operation that cannot be interrupted, or is resumable. For a complex system
I would imagine you will need to deal with all the intricacies this
synchronization involves - querying each to determine if it is in a state
suitable to be unloaded, requesting it get to that state if it is not ready
to be shutdown, etc.

I don't know how many resources each appdomain consumes - I don't think it
would be an issue unless you are dealing with large numbers of appdomains
(of course, this begs the question of how many constitutes a "large"
system).

I think it's easier to manage the issues with a single appdomain, but this
also means that you must unload all the plugins to unload any of them.

"stu_pb" <st****@discuss ions.microsoft. com> wrote in message
news:57******** *************** ***********@mic rosoft.com...
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 thought was to use System.Reflecti on.Assembly.Loa d to load the
plugins dynamically. This worked great, but I was left with no way to
dynamically unload the plugin.

So now I come to creating a new AppDomain for the plugins to reside in,
since the AppDomain can be unloaded. The problem I see with this is that
when I dynamically unload one plugin, the rest will have to be reloaded
and
any data will be lost. Is that true? I could notify the plugin when it
is
going to be unloaded and it could persist itself, or I could persist each
plugin automatically I suppose.

So I thought I could have an AppDomain for each plugin. Is this feasible?
Would this take up too many resources? Also in this case I would have to
have one instance of the assembly loader for each plugin since the
assembly
should be loaded from inside the current application domain.

I guess I am just looking for some opinions as to which approach is the
best, easiest or hopefully both!

Thanks for your help!

Jul 21 '05 #2
Thanks for the great reply!

I am still in the design phase of the app and I believe from what I have
read, and what you said, that I will use a single AppDomain and allow the
plugins the chance to serialize themselves before being unloaded.

I suppose that if some data was lost when the AppDomain is unloaded it is
not the end of the world, this should happen rarely, I can't imagine plugins
being unloaded frequently!

Here's another question then: do you think it would be possible/reasonable
for the application to automatically handle the serialization of the plugins
when one plugin is reloaded? This assumes that the Plugins are designed to
be serializable and that serialization works properly across AppDomains.
This way the unload/reload could happen transparently to the plugins
themselves (unless of course the plugins are doing some processing at the
time!).

Thanks again!

"David Levine" wrote:
Using appdomains to isolate plugins is essentially using remoting. My
approach has been to use a single appdomain for all plugins wherever
possible and only use separate appdomains when needed. The side effect of
this grouping is that all plugins in the same appdomain will get unloaded at
the same time. You could put each plugin into a separate appdomain but this
creates its own set of problems - each plugin is now remoted to all other
objects in other appdomains. When using separate appdomains you will need to
deal with issues related to assembly probing and versioning, resolving
references to other assemblies, ensuring that versioning differences in
common/shared assemblies are dealt with, etc.

If you are still in the design phase then you could add
serialize/deserialize methods to the plugin API to aid in preserving the
state. However, this assumes that a plugin is not in the middle of an
operation that cannot be interrupted, or is resumable. For a complex system
I would imagine you will need to deal with all the intricacies this
synchronization involves - querying each to determine if it is in a state
suitable to be unloaded, requesting it get to that state if it is not ready
to be shutdown, etc.

I don't know how many resources each appdomain consumes - I don't think it
would be an issue unless you are dealing with large numbers of appdomains
(of course, this begs the question of how many constitutes a "large"
system).

I think it's easier to manage the issues with a single appdomain, but this
also means that you must unload all the plugins to unload any of them.

"stu_pb" <st****@discuss ions.microsoft. com> wrote in message
news:57******** *************** ***********@mic rosoft.com...
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 thought was to use System.Reflecti on.Assembly.Loa d to load the
plugins dynamically. This worked great, but I was left with no way to
dynamically unload the plugin.

So now I come to creating a new AppDomain for the plugins to reside in,
since the AppDomain can be unloaded. The problem I see with this is that
when I dynamically unload one plugin, the rest will have to be reloaded
and
any data will be lost. Is that true? I could notify the plugin when it
is
going to be unloaded and it could persist itself, or I could persist each
plugin automatically I suppose.

So I thought I could have an AppDomain for each plugin. Is this feasible?
Would this take up too many resources? Also in this case I would have to
have one instance of the assembly loader for each plugin since the
assembly
should be loaded from inside the current application domain.

I guess I am just looking for some opinions as to which approach is the
best, easiest or hopefully both!

Thanks for your help!


Jul 21 '05 #3
stu_pb,
In addition to the other comments, the following MSDN Magazine article
discusses using AppDomains for plug-ins...

http://msdn.microsoft.com/msdnmag/is...s/default.aspx

Hope this helps
Jay

"stu_pb" <st****@discuss ions.microsoft. com> wrote in message
news:57******** *************** ***********@mic rosoft.com...
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 thought was to use System.Reflecti on.Assembly.Loa d to load the
plugins dynamically. This worked great, but I was left with no way to
dynamically unload the plugin.

So now I come to creating a new AppDomain for the plugins to reside in,
since the AppDomain can be unloaded. The problem I see with this is that
when I dynamically unload one plugin, the rest will have to be reloaded
and
any data will be lost. Is that true? I could notify the plugin when it
is
going to be unloaded and it could persist itself, or I could persist each
plugin automatically I suppose.

So I thought I could have an AppDomain for each plugin. Is this feasible?
Would this take up too many resources? Also in this case I would have to
have one instance of the assembly loader for each plugin since the
assembly
should be loaded from inside the current application domain.

I guess I am just looking for some opinions as to which approach is the
best, easiest or hopefully both!

Thanks for your help!

Jul 21 '05 #4

"stu_pb" <st***@discussi ons.microsoft.c om> wrote in message
news:AE******** *************** ***********@mic rosoft.com...
Thanks for the great reply!

I am still in the design phase of the app and I believe from what I have
read, and what you said, that I will use a single AppDomain and allow the
plugins the chance to serialize themselves before being unloaded.

I suppose that if some data was lost when the AppDomain is unloaded it is
not the end of the world, this should happen rarely, I can't imagine
plugins
being unloaded frequently!
How could data get lost?
Here's another question then: do you think it would be possible/reasonable
for the application to automatically handle the serialization of the
plugins
when one plugin is reloaded? This assumes that the Plugins are designed
to
be serializable and that serialization works properly across AppDomains.
This way the unload/reload could happen transparently to the plugins
themselves (unless of course the plugins are doing some processing at the
time!).

When you say the app handles the serialization for the plugin, do you mean
that it invokes the serialization method, or it actually performs the
serialization on behalf of the plugin? I'd be leary of trying to
serialize/deserialize on behalf of a plugin, because this will be setting
the state of the plugin and I don't believe an app can determine if it is
safe or correct to set the state of an unknown class unless you know it is
explicitly designed to support that. It's not that you can't do it, it just
seems like there are a lot of ways for this to fail. For one thing, the
plugin may have values in private fields that are not directly serliazable
yet are part of its state. For another, a plugin may have to perform a
complex initialization of another device - simply setting state wont do
this.

If it were me I would invoke a serialize/deserialize method and let the
plugin handle it itself.

I would not assume you can serialize across appdomains. For that to work all
the types the remote appdomain uses must be available to the other appdomain
doing the serliazation on its behalf, and there are a lot of ways for this
to go wrong. Again, it's not that you can't do it, its just that there are
side-issues that you will run into if you do this. Instead, you can
serialize an object into a byte stream and pass that around without a
problem, but only one side understands the contents of that stream. This
would allow you to centralize the data storage for all plugins without the
side effects.
Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2877
by: Arnaud Debaene | last post by:
Hello group. I have an app which can load "plugins" assemblies that are described in the registry (each registry entry gives the full path to the plugin ..dll file). The plugins may be anywhere on the disk. Each plugin defines a class which implements an interface known to the app. The main app loads the plugin with Assembly.LoadFrom and then uses Assembly.GetTypes() and Type.FindInterface to find the concrete types in the plugin that...
1
4109
by: MatthewRoberts | last post by:
Howdy All, I am having difficulty with two-way communication across AppDomains in an attempt to dynamically script applications. Everything works as expected, except when using ByRef parameters. The below explanation is lengthy, but well worth the read. If you can help me, I'd gladly share this code which has greatly helped my development of extensible applications.
4
2354
by: Chris Lacey | last post by:
Hi, I'm currently writing a scheduling service which starts a number DotNet executables, each within a new AppDomain, every ten seconds. The guts of the code is as follows: // For each executable in the list of tasks for (int i = 0; i < this.processTasks.Length; i++) {
2
10846
by: Lauren Hines | last post by:
Hello, I have read numerous post stating that the only way to unload an assembly (DLL in my case) is to create a separate AppDomain, load the assembly, then unload it by calling AppDomain.Unload. When trying to delete the DLL file I get an exception that access is denied. When trying to copy over the DLL file, I get an exception that it is being used by another process.
6
4501
by: Pete Davis | last post by:
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...
0
1114
by: Jack Wright | last post by:
Dear All, I read the following post in this newsgroup...dated 2003-02-24 19:13:03 >>> I'm trying to kill an ASP.NET web application by using the following code. When KillAppDomain webmethod is called it will kill the AppDomain specified. The problem is once I kill an application, I couldn't start that application again. Any help on how to safely kill an web application without affecting others is much appreciated.
4
314
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 thought was to use System.Reflection.Assembly.Load to load the plugins dynamically. This worked great, but I was left with no way to dynamically unload the plugin. So now I come to creating a new AppDomain for the plugins to reside in, since the...
1
2234
by: dscriv | last post by:
Hello, I have Netscape 8.0.4 (in Firefox mode) and Flash 8.0.24.0. I also have IE and Firefox installed. If I go to this page, which contains a Flash detection movie: http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_15507 all three browers successfully run the Flash movie and show the same version of Flash to be installed. However, if I try to use a javascript Flash detection solution, it does
12
8256
by: John | last post by:
I have a AppDomain ID, how do I get the instance of the AppDomain Object? Please advice. Thanks in advance. John
0
8586
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9004
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8864
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8838
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7684
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.