From 86092fc955b696243d75df44bb8f09cb38e34e28 Mon Sep 17 00:00:00 2001 From: Kukks Date: Mon, 3 May 2021 08:35:54 +0200 Subject: [PATCH] Wrap more plugin loading logic in try catch to not crash fatally --- BTCPayServer/Plugins/PluginManager.cs | 48 ++++++++++++++++----------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/BTCPayServer/Plugins/PluginManager.cs b/BTCPayServer/Plugins/PluginManager.cs index 183b76e00..2d557102a 100644 --- a/BTCPayServer/Plugins/PluginManager.cs +++ b/BTCPayServer/Plugins/PluginManager.cs @@ -76,8 +76,8 @@ namespace BTCPayServer.Plugins } var disabledPlugins = GetDisabledPlugins(pluginsFolder); - - + + foreach (var dir in orderedDirs) { @@ -94,24 +94,34 @@ namespace BTCPayServer.Plugins continue; } - var plugin = PluginLoader.CreateFromAssemblyFile( - pluginFilePath, // create a plugin from for the .dll file - config => - { - - // this ensures that the version of MVC is shared between this app and the plugin - config.PreferSharedTypes = true; - config.IsUnloadable = true; - }); + try + { - mvcBuilder.AddPluginLoader(plugin); - var pluginAssembly = plugin.LoadDefaultAssembly(); - _pluginAssemblies.Add(pluginAssembly); - _plugins.Add(plugin); - var fileProvider = CreateEmbeddedFileProviderForAssembly(pluginAssembly); - loadedPlugins.Add((plugin, pluginAssembly, fileProvider)); - plugins.AddRange(GetAllPluginTypesFromAssembly(pluginAssembly) - .Select(GetPluginInstanceFromType)); + var plugin = PluginLoader.CreateFromAssemblyFile( + pluginFilePath, // create a plugin from for the .dll file + config => + { + + // this ensures that the version of MVC is shared between this app and the plugin + config.PreferSharedTypes = true; + config.IsUnloadable = true; + }); + + mvcBuilder.AddPluginLoader(plugin); + var pluginAssembly = plugin.LoadDefaultAssembly(); + _pluginAssemblies.Add(pluginAssembly); + _plugins.Add(plugin); + var fileProvider = CreateEmbeddedFileProviderForAssembly(pluginAssembly); + loadedPlugins.Add((plugin, pluginAssembly, fileProvider)); + plugins.AddRange(GetAllPluginTypesFromAssembly(pluginAssembly) + .Select(GetPluginInstanceFromType)); + + } + catch (Exception e) + { + _logger.LogError(e, + $"Error when loading plugin {pluginName}"); + } } foreach (var plugin in plugins)