0

I have an mvc3 application. I have a subfolder in my application project called "Plugins"

All of the dll's stored in that folder should be updateable during runtime, so then we an put down the appdomain and reload the new version of the dlls, so I am attemping to load all the plugin dll's in a different appDomain and set it's shadowCopy properties.

Looking through SO, msdn and some blogs, I got to this "solution". (this is called during my Application_Start)

static AppDomain pluginDomain;
static PluginHolder()
        {
            AppDomainSetup domainSetup = AppDomain.CurrentDomain.SetupInformation;
            domainSetup.ApplicationName = "Plugins";
            domainSetup.PrivateBinPathProbe = domainSetup.PrivateBinPath;
            domainSetup.PrivateBinPath = GetPluginsDirectory();
            domainSetup.ShadowCopyFiles = "true";
            domainSetup.ShadowCopyDirectories = domainSetup.PrivateBinPath;

            pluginDomain= AppDomain.CreateDomain("Plugins", null, domainSetup);
            var item = pluginDomain.Load(File.ReadAllBytes(GetPluginsDirectory() + "Item.dll"));
        }

"Item.dll" is the dll i am attemping to load. The last line throws a "Could not load file or assembly Item or one of its dependencies". This seems to be the way other people have succeded with, but it just wont work for me.

I have no previous experience with AppDomains, so I am not sure on how to approach this problem, or if I am tackling it correctly.

Is my Assembly loading via the new AppDomain an ok approach?

Xavier Guzman
  • 460
  • 3
  • 11

1 Answers1

0

To decypher these kind of error messages, you should use the Assembly Binding Log Viewer.

Also pay attention on the remarks section on the documentation page of AppDomain.Load(byte[]). If you want to load the assembly on the new AppDomain, then you should use CreateInstanceAndUnwrap instead.

If you want to implement a plugin engine in .NET, then you will need to understand AppDomains, assembly resolving and loading and a then choose on a mechanism for the communication between objects from different AppDomains. Most good books on .NET and CLR include a chapter or two on AppDomains and they will get you up to speed. Now as far as the cross-AppDomain communication is concerned, you could use WCF or .NET Remoting (MarshalByRefObject).

Good luck.

Panos Rontogiannis
  • 4,154
  • 1
  • 24
  • 29