question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make plugins unloadable

See original GitHub issue

This will require .NET Core 3.0 and up, which has added libraries to make assembly load contexts unloadable.

See https://github.com/dotnet/coreclr/issues/552, https://github.com/dotnet/coreclr/pull/18476, https://github.com/dotnet/corefx/issues/14724, and https://github.com/dotnet/coreclr/projects/9.


Update

Merged #31 which adds API when using .NET Core 3.0 to allow unloading.

Usage

Unloadable plugins is supported in .NET Core 3.0 Preview 2 and newer. To unload a plugin, make sure isUnloadable = true and dispose the loader to trigger the unload.

var loader = PluginLoader.CreateFromAssemblyFile(
                    pluginDll,
                    sharedTypes: new [] { typeof(IPlugin) },
                    isUnloadable: true);
// do stuff

loader.Dispose(); // this triggers an unload

In order for this to work, you must make sure you have not left behind any variables (static, local, etc) or manually allocated memory. Once GC has collected everything, the assembly will be unloaded. See https://github.com/dotnet/coreclr/pull/22221

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
natemcmastercommented, Feb 6, 2019

Initial implementation #31.

Usage

Unloadable plugins is supported in .NET Core 3.0 Preview 2 and newer. To unload a plugin, dispose the loader.

var loader = PluginLoader.CreateFromAssemblyFile(
                    pluginDll,
                    sharedTypes: new [] { typeof(IPlugin) });
// do stuff

loader.Dispose(); // this triggers an unload
2reactions
natemcmastercommented, Mar 26, 2019

Merged #31 which adds API when using .NET Core 3.0 to allow unloading.

Usage

Unloadable plugins is supported in .NET Core 3.0 Preview 2 and newer. To unload a plugin, make sure isUnloadable = true and dispose the loader to trigger the unload.

var loader = PluginLoader.CreateFromAssemblyFile(
                    pluginDll,
                    sharedTypes: new [] { typeof(IPlugin) },
                    isUnloadable: true);
// do stuff

loader.Dispose(); // this triggers an unload

In order for this to work, you must make sure you have not left behind any variables (static, local, etc) or manually allocated memory. Once GC has collected everything, the assembly will be unloaded. See https://github.com/dotnet/coreclr/pull/22221

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unloadable Plugins
Creating a plugin architecture in .NET is pretty easy. Unless you need to unload the plugins - AppDomain.Unload just does not work.
Read more >
1.15.2 - How can I unload a Plugin?
I'm currently trying to program a PluginManager GUI and unfortunately I don't know how to unload a plugin and not disable it.
Read more >
C# Load/Unload plugins
Is there anyway to have ClassLibrary plugins which can be loaded/unloaded. The only way I have found is using an AppDomain but that...
Read more >
Unloading & Reloading Plugin
I am making a plugin that will be able to unload, load, and reload any specific plugin without the use of /reload.
Read more >
Unload plugins from dashboard
Hello, I'm the “In the dashboard” tool to set unload rules for the admin ... I tried unchecking the “Make an exception” and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found