views:

147

answers:

3

Hello everybody,

I need to implement a plugin architecture within c#/.net in order to load

  • custom user defined actions
  • data type handling code for a custom data grid / conversion / ...

from non-static linked assembly files.

Because the application has to handle many custom user defined actions, Iam in need for unloading them once executed in order to reduce memory usage.

I found several good articles about plugin architectures, eg:

but none of them gave me enough sausage for properly unloading an assembly.

As the program is to be distributed and the user defined actions are (as the name states) user defined: how to i prevent the assembly from executing malicious code (eg. closing my progra, deleting files)?

Are there any other pitfalls one of you has encountered?

+2  A: 

One technique is to load the additional assemblies into a separate AppDomain. Unloading the AppDomain will unload the assemblies.

John Saunders
+1  A: 

You can't unload a single assembly. You can only unload a group of assemblies by unloading the AppDomain they are a part of.

This is essentially how SQL CLR works, and ASP.NET -- by having a transient AppDomain for user-supplied assemblies.

Alex
+3  A: 

Have you thought about using the Add-Ins and Extensiblity framework from MS? http://msdn.microsoft.com/en-us/magazine/cc163476.aspx

Michael

Michael Ulmann
@Michael: does this framework handle the unloading problem?
John Saunders
@John: Managed Addin Framework uses AppDomains to implement the plugin architecture and yes, it will handle unloading. Although there's quite a lot of code to write, it does a good way in abstracting away the AppDomain logic from your code.
siz
Thank you, looks like what i need!
henchman