public PluginContainer GetPlugin(string path, ILogger logger) { var loadContext = new PluginLoadContext(Path.GetFileNameWithoutExtension(path) + "LoadContext", path); var assembly = loadContext.LoadFromAssemblyPath(path); return(HandlePlugin(loadContext, assembly, path, logger)); }
internal static Assembly LoadPluginAssembly(this FileInfo file) { var loadContext = new PluginLoadContext(file.FullName); var assembly = loadContext.LoadFromAssemblyPath(file.FullName); return(assembly); }
static void Main(string[] args) { var aaa = Path.GetFullPath(Path.Combine(typeof(Program).Assembly.Location, @"../../../../../NLogTest/bin/Debug/netcoreapp3.1/NLogTest.dll")); var loader = new PluginLoadContext(aaa); var ass = loader.LoadFromAssemblyPath(aaa); var pg2 = ass.GetType("NLogTest.Program"); pg2.GetMethod("Main", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[] { Array.Empty <string>() }); }
public Tuple <PluginLoadContext, Assembly> GetAssemblyAndLoadContext(string path) { var pluginLoadContext = new PluginLoadContext(); var assembly = pluginLoadContext.LoadFromAssemblyPath(path); if (assembly is null) { throw new PluginException($"[{nameof(GetAssemblyAndLoadContext)}] Error: Could not load the assembly under the given path: {path}"); } return(new Tuple <PluginLoadContext, Assembly>(pluginLoadContext, assembly)); }