DotNetCorePlugins icon indicating copy to clipboard operation
DotNetCorePlugins copied to clipboard

EnableHotReload error handling

Open devna13 opened this issue 3 years ago • 1 comments

I'm new to this awesome repo, and using EnableHotReload to update plugins on the fly similar to your hot reload sample

  loader = PluginLoader.CreateFromAssemblyFile(
                            pluginDllPath,
                            sharedTypes: new[] {
                               typeof(IPluginMessageHandler),
                               //typeof(IServiceCollection),
                               typeof(ILogger)
                            },
                            isUnloadable: true,
                            configure: config => config.EnableHotReload = true);

everything works great but I ran into an edge case; If I publish a bad plugin, that doesn't have all of it's dependencies, it causes the host app to crash with this CLR exception

Fatal error. Internal CLR error. (0x80131506)
   at System.Runtime.Loader.AssemblyLoadContext.PrepareForAssemblyLoadContextRelease(IntPtr, IntPtr)
   at System.Runtime.Loader.AssemblyLoadContext.InitiateUnload()
   at System.Runtime.Loader.AssemblyLoadContext.Unload()
   at McMaster.NETCore.Plugins.PluginLoader.Reload()
   at McMaster.NETCore.Plugins.Internal.Debouncer+<>c__DisplayClass4_0.<Execute>b__0(System.Threading.Tasks.Task)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()

I was wondering if wrapping this line in try catch would resolve it, or there is a better way to prevent host from crashing

https://github.com/natemcmaster/DotNetCorePlugins/blob/452f8d306ef17c84c8b02b948e93eb95ef182be3/src/Plugins/PluginLoader.cs#L225

Thanks

devna13 avatar Aug 19 '21 23:08 devna13

I'll mark this as 'help wanted'. There are probably better ways to handle these errors and would be open to contributions to improve it.

(FYI - this project is in maintenance mode right now. See #117 for detail on what the applied labels indicate.)

natemcmaster avatar Nov 13 '21 05:11 natemcmaster

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.

github-actions[bot] avatar Nov 14 '22 02:11 github-actions[bot]

Closing due to inactivity. If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.

github-actions[bot] avatar Nov 29 '22 02:11 github-actions[bot]