@@ -21,7 +21,7 @@ public static class PluginsLoader
2121
2222 public static List < PluginPair > Plugins ( List < PluginMetadata > metadatas , PluginsSettings settings )
2323 {
24- var dotnetPlugins = DotNetPlugins ( metadatas ) . ToList ( ) ;
24+ var dotnetPlugins = DotNetPlugins ( metadatas ) ;
2525 var pythonPlugins = PythonPlugins ( metadatas , settings . PythonDirectory ) ;
2626 var executablePlugins = ExecutablePlugins ( metadatas ) ;
2727 var plugins = dotnetPlugins . Concat ( pythonPlugins ) . Concat ( executablePlugins ) . ToList ( ) ;
@@ -46,75 +46,58 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
4646 var type = types . First ( o => o . IsClass && ! o . IsAbstract && o . GetInterfaces ( ) . Contains ( typeof ( IPlugin ) ) ) ;
4747 var plugin = ( IPlugin ) Activator . CreateInstance ( type ) ;
4848#else
49- Assembly assembly ;
49+ Assembly assembly = null ;
50+ IPlugin plugin = null ;
51+
5052 try
5153 {
5254 assembly = AssemblyLoadContext . Default . LoadFromAssemblyPath ( metadata . ExecuteFilePath ) ;
53- }
54- catch ( Exception e )
55- {
56- erroredPlugins . Add ( metadata . Name ) ;
5755
58- Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Couldn't load assembly for the plugin: { metadata . Name } ", e ) ;
59- return ;
60- }
56+ var types = assembly . GetTypes ( ) ;
57+ var type = types . First ( o => o . IsClass && ! o . IsAbstract && o . GetInterfaces ( ) . Contains ( typeof ( IPlugin ) ) ) ;
6158
62- Type type ;
63- try
59+ plugin = ( IPlugin ) Activator . CreateInstance ( type ) ;
60+ }
61+ catch ( Exception e ) when ( assembly == null )
6462 {
65- var types = assembly . GetTypes ( ) ;
66-
67- type = types . First ( o => o . IsClass && ! o . IsAbstract && o . GetInterfaces ( ) . Contains ( typeof ( IPlugin ) ) ) ;
63+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Couldn't load assembly for the plugin: { metadata . Name } ", e ) ;
6864 }
6965 catch ( InvalidOperationException e )
7066 {
71- erroredPlugins . Add ( metadata . Name ) ;
72-
7367 Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Can't find the required IPlugin interface for the plugin: <{ metadata . Name } >", e ) ;
74- return ;
7568 }
7669 catch ( ReflectionTypeLoadException e )
7770 {
78- erroredPlugins . Add ( metadata . Name ) ;
79-
8071 Log . Exception ( $ "|PluginsLoader.DotNetPlugins|The GetTypes method was unable to load assembly types for the plugin: <{ metadata . Name } >", e ) ;
81- return ;
8272 }
83-
84- IPlugin plugin ;
85- try
73+ catch ( Exception e )
8674 {
87- plugin = ( IPlugin ) Activator . CreateInstance ( type ) ;
75+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|The following plugin has errored and can not be loaded: < { metadata . Name } >" , e ) ;
8876 }
89- catch ( Exception e )
77+
78+ if ( plugin == null )
9079 {
9180 erroredPlugins . Add ( metadata . Name ) ;
92-
93- Log . Exception ( $ "|PluginsLoader.DotNetPlugins|The following plugin has errored and can not be loaded: <{ metadata . Name } >", e ) ;
9481 return ;
9582 }
9683#endif
97- PluginPair pair = new PluginPair
84+ plugins . Add ( new PluginPair
9885 {
9986 Plugin = plugin ,
10087 Metadata = metadata
101- } ;
102- plugins . Add ( pair ) ;
88+ } ) ;
10389 } ) ;
10490 metadata . InitTime += milliseconds ;
105-
10691 }
10792
10893 if ( erroredPlugins . Count > 0 )
10994 {
110- var errorPluginString = "" ;
95+ var errorPluginString = String . Join ( Environment . NewLine , erroredPlugins ) ;
11196
11297 var errorMessage = "The following "
11398 + ( erroredPlugins . Count > 1 ? "plugins have " : "plugin has " )
11499 + "errored and cannot be loaded:" ;
115100
116- erroredPlugins . ForEach ( x => errorPluginString += x + Environment . NewLine ) ;
117-
118101 Task . Run ( ( ) =>
119102 {
120103 MessageBox . Show ( $ "{ errorMessage } { Environment . NewLine } { Environment . NewLine } " +
0 commit comments