@@ -194,7 +194,17 @@ public static Assembly LoadAssembly(string name)
194194 Assembly assembly = null ;
195195 try
196196 {
197- assembly = Assembly . Load ( name ) ;
197+ var importEvent = new ImplicitAssemblyLoadingEventArgs ( name ) ;
198+ if ( importEvent . SkipAssemblyLoad )
199+ {
200+ return null ;
201+ }
202+
203+ PythonEngine . RaiseAssemblyAsModuleImportingEvent ( importEvent ) ;
204+ if ( ! importEvent . SkipAssemblyLoad )
205+ {
206+ assembly = Assembly . Load ( name ) ;
207+ }
198208 }
199209 catch ( Exception )
200210 {
@@ -341,8 +351,17 @@ internal static void ScanAssembly(Assembly assembly)
341351 // A couple of things we want to do here: first, we want to
342352 // gather a list of all of the namespaces contributed to by
343353 // the assembly.
354+ Type [ ] types = new Type [ 0 ] ;
355+ try
356+ {
357+ types = assembly . IsDynamic ? assembly . GetTypes ( ) : assembly . GetExportedTypes ( ) ;
358+ }
359+ catch ( TypeLoadException )
360+ {
361+ // Do nothing.
362+ // This problem usually occurs when transitive dependencies have references to older packages than main application.
363+ }
344364
345- Type [ ] types = assembly . GetTypes ( ) ;
346365 foreach ( Type t in types )
347366 {
348367 string ns = t . Namespace ?? "" ;
@@ -417,12 +436,15 @@ public static List<string> GetNames(string nsname)
417436 {
418437 foreach ( Assembly a in namespaces [ nsname ] . Keys )
419438 {
420- Type [ ] types = a . GetTypes ( ) ;
439+ Type [ ] types = a . IsDynamic ? a . GetTypes ( ) : a . GetExportedTypes ( ) ;
421440 foreach ( Type t in types )
422441 {
423442 if ( ( t . Namespace ?? "" ) == nsname )
424443 {
425- names . Add ( t . Name ) ;
444+ if ( ! t . IsNested )
445+ {
446+ names . Add ( t . Name ) ;
447+ }
426448 }
427449 }
428450 }
0 commit comments