From 6ddfdc4b38c280995637bb42802db03198e7c6ce Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 8 Apr 2021 13:54:06 -0600 Subject: [PATCH 1/2] Updating plugin loading mechanism to provide better feedback --- .../Plugins/PluginLoader.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs index 01da1c54..c0aac87d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs @@ -363,9 +363,10 @@ namespace PepperDash.Essentials { try { - if (typeof(IPluginDeviceFactory).IsAssignableFrom(type)) + if (typeof (IPluginDeviceFactory).IsAssignableFrom(type)) { - var plugin = (IPluginDeviceFactory)Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); + var plugin = + (IPluginDeviceFactory) Crestron.SimplSharp.Reflection.Activator.CreateInstance(type); LoadCustomPlugin(plugin, loadedAssembly); } else @@ -378,18 +379,30 @@ namespace PepperDash.Essentials } } } + catch (NotSupportedException e) + { + //this happens for dlls that aren't PD dlls, like ports of Mono classes into S#. Swallowing. + + } catch (Exception e) { Debug.Console(2, "Load Plugin not found. {0}.{2} is not a plugin factory. Exception: {1}", - loadedAssembly.Name, e, type.Name); - continue; + loadedAssembly.Name, e.Message, type.Name); } } } + catch (TypeLoadException e) + { + Debug.Console(0, Debug.ErrorLogLevel.Warning, "Unable to load assembly {0}: {1}", + loadedAssembly.Name, e.Message); + Debug.Console(2, e.StackTrace); + } catch (Exception e) { - Debug.Console(2, "Error Loading Assembly: {0} Exception: {1} ", loadedAssembly.Name, e); + Debug.Console(0, Debug.ErrorLogLevel.Warning, "Error Loading assembly {0}: {1}", + loadedAssembly.Name, e.Message); + Debug.Console(2, "{0}", e.StackTrace); continue; } } From 8cfd58bb7e25c4476d21cee2d06e4420022b02e7 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 8 Apr 2021 14:21:32 -0600 Subject: [PATCH 2/2] Fix error printing for plugin loading --- .../Plugins/PluginLoader.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs index c0aac87d..7192c667 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Plugins/PluginLoader.cs @@ -358,7 +358,19 @@ namespace PepperDash.Essentials try { var assy = loadedAssembly.Assembly; - var types = assy.GetTypes(); + CType[] types = {}; + try + { + types = assy.GetTypes(); + } + catch (TypeLoadException e) + { + Debug.Console(0, Debug.ErrorLogLevel.Warning, "Unable to get types for assembly {0}: {1}", + loadedAssembly.Name, e.Message); + Debug.Console(2, e.StackTrace); + continue; + } + foreach (var type in types) { try @@ -382,7 +394,7 @@ namespace PepperDash.Essentials catch (NotSupportedException e) { //this happens for dlls that aren't PD dlls, like ports of Mono classes into S#. Swallowing. - + } catch (Exception e) { @@ -392,12 +404,6 @@ namespace PepperDash.Essentials } } - catch (TypeLoadException e) - { - Debug.Console(0, Debug.ErrorLogLevel.Warning, "Unable to load assembly {0}: {1}", - loadedAssembly.Name, e.Message); - Debug.Console(2, e.StackTrace); - } catch (Exception e) { Debug.Console(0, Debug.ErrorLogLevel.Warning, "Error Loading assembly {0}: {1}",