I'm using a 3rd party library in my project. My project also has a plugin system that allows users to create their own plugins that are loaded dynamically at runtime:
var plugin = Assembly.LoadFrom(pathToPluginDLL);
// later on, the constructor from the user plugin is loaded
pluginConstructor.Invoke();
I've got a scenario that one of these user plugins is referencing the same 3rd party library that my main project uses. That 3rd party library has a static object that needs to be unique for the main project and unique for the user plugin.
Here's a quick contrived code example of what happens:
// This is a class within a 3rd party DLL, referenced directly from the main project
public class SomeClassWithStaticObjects
public static string staticString {get; set;}
}
// In the main project
SomeClassWithStaticObjects.staticString = "main project static string";
In one of the user plugins that references the same 3rd party DLL:
SomeClassWithStaticObjects.staticString = "plugin project static string";
The problem being that SomeClassWithStaticObjects.staticString
is referencing the same static object between the main project and the plugin that's loaded using reflection. Is there a way that I can "isolate" the user plugin in it's own memory space so that it has it's own unique version of the static class?