Reputation: 79
I know the there is plenty of threads about loading plugins in new app domain. My fault I didn't read them before.. I have this school project - plugin based app, which is almost done. Except one important point - plugins has to be loaded in new domain.. I create plugin based app using this article http://www.codeproject.com/Articles/6334/Plug-ins-in-C
I'm currently in time press with project deadline and i'm stucked with plugin in same application domain. could you please advice me if it's possible to do some simple changes to application in link to load plugins in separate app domain? I really dont wont to write the app from start. :(
Thank you for all your advices.
Upvotes: 1
Views: 4493
Reputation: 3960
Try this
AppDomain domain = AppDomain.CreateDomain("domain name");
// TODO: configure appdomain as needed
// to load the dll and get a type you can reference in your current appdomain
string pathToDll = @"C:\somedir\Mydll.dll";
Type myType = typeof(SomeType);
SomeType myObj = (SomeType)domain.CreateInstanceFromAndUnwrap(pathToDll, myType.FullName);
// to just load the dll into the new appdomain
byte[] file = File.ReadAllBytes(pathToDll);
domain.Load(file);
Upvotes: 2
Reputation: 22739
You can use System.Addin. Take a look at this sample (or others from this CodePlex page)
http://clraddins.codeplex.com/releases/view/9454
Upvotes: 0
Reputation: 2884
I once tried to divide my WinForms application into separate AppDomains and it wasn't easy at all. However, in your case it should not be very difficult.
Try to create a new AppDomain and load your plug-in type in it. Then communicate with that object using reflection or a common base interface (remeber that you cannot reference the plug-in type in your host application if you want to avoid loading the plugin assembly into the host AppDomain).
You might also want to look at the System.AddIn namespace - it was implemented specifically to make plugin development easy.
Upvotes: 1