Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improve loader robustness
Ignore and print loader error and proceed with loading if possible.
  • Loading branch information
sefgit committed Dec 26, 2023
commit ca105f93411005d13c0d58a3298984706d50ecb0
27 changes: 27 additions & 0 deletions src/runtime/AssemblyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ internal static Type[] GetTypes(Assembly a)
catch (ReflectionTypeLoadException exc)
{
// Return all types that were successfully loaded
foreach (var item in exc.LoaderExceptions)
{
System.Console.Error.WriteLine("[pythonnet] {0}", item.Message);
}
return exc.Types.Where(x => x != null && IsExported(x)).ToArray();
}
}
Expand All @@ -425,8 +429,31 @@ internal static Type[] GetTypes(Assembly a)
}
catch (FileNotFoundException)
{
System.Console.Error.WriteLine("[pythonnet] {0} File not found", a.GetName());
return new Type[0];
}
catch (System.TypeLoadException e)
{
try
{
return a.GetTypes().Where(IsExported).ToArray();
}
catch (ReflectionTypeLoadException exc)
{
foreach (var item in exc.LoaderExceptions)
{
System.Console.Error.WriteLine("[pythonnet] {0}", item.Message);
}
// Return all types that were successfully loaded
return exc.Types.Where(x => x != null && IsExported(x)).ToArray();
}
}
catch (Exception e) // System.TypeLoadException
{
System.Console.Error.WriteLine("[pythonnet] {0} {1}", a.GetName(), e);
return new Type[0];
}

}
}

Expand Down