diff --git a/src/Neo/Plugins/Plugin.cs b/src/Neo/Plugins/Plugin.cs index 0140659096..fb7bc28e2a 100644 --- a/src/Neo/Plugins/Plugin.cs +++ b/src/Neo/Plugins/Plugin.cs @@ -168,7 +168,21 @@ protected IConfigurationSection GetConfiguration() private static void LoadPlugin(Assembly assembly) { - foreach (var type in assembly.ExportedTypes) + Type[] exportedTypes; + + var assemblyName = assembly.GetName().Name; + + try + { + exportedTypes = (Type[])assembly.ExportedTypes; + } + catch (Exception ex) + { + Utility.Log(nameof(Plugin), LogLevel.Error, $"Failed to load plugin assembly {assemblyName}: {ex}"); + throw; + } + + foreach (var type in exportedTypes) { if (!type.IsSubclassOf(typeof(Plugin))) continue; if (type.IsAbstract) continue; @@ -182,7 +196,7 @@ private static void LoadPlugin(Assembly assembly) } catch (Exception ex) { - Utility.Log(nameof(Plugin), LogLevel.Error, ex); + Utility.Log(nameof(Plugin), LogLevel.Error, $"Failed to initialize plugin type {type.FullName} of {assemblyName}: {ex}"); } } } @@ -199,7 +213,10 @@ internal static void LoadPlugins() { assemblies.Add(Assembly.Load(File.ReadAllBytes(filename))); } - catch { } + catch (Exception ex) + { + Utility.Log(nameof(Plugin), LogLevel.Error, $"Failed to load plugin assembly file {filename}: {ex}"); + } } }