Search code examples
c#mafsystem.addin

C# MAF Activate AddIn without locking dll


Using System.AddIn, is there a way to load and activate an AddIn without locking the .dll file? I want to delete or override the file to load a new version of my AddIn.

The only way to unlock the file at this moment is shutting down the AddIn. But I need to keep it always alive for incoming calls (Async-service, yes, a nightmare).

Or maybe there's another way to update AddIns at runtime, and I'm not doing it right. I'd like to know wich can be the correct way to do this. Thanks!


Solution

  • What about the ShadowCopy functionality of the System.AppDomain class?

    I haven't given it a try yet, but you could try the following:

    1. Create an AppDomainSetup.
    2. In the AppDomainSetup instance set ShadowCopyFiles to true.
    3. In the AppDomainSetup instance set ShadowCopyFilesDirectories to the directory path(s) that contain the assemblies you want to be able to ovewrite at run time. This could simply be the directory where the add-in assembly is located. You should experiment a bit.
    4. In the AppDomainSetup instance set everything else according to your needs.
    5. Use this overload of AppDomain.CreateAppDomain to create the new application domain.
    6. Load the add-in using this overload of AddInToken.LoadAddIn

    You can find more info on shadow copying here. Also read this thread at System.AddIn Tools and Samples page at CodePlex.