Skip to content
Prev Previous commit
Next Next commit
Catch exceptions during type loading
  • Loading branch information
filmor committed Nov 14, 2018
commit 76314725be60ca0e49a39dcbc4405ae7c7281097
26 changes: 23 additions & 3 deletions src/runtime/assemblymanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;

Expand Down Expand Up @@ -470,9 +471,28 @@ public static Type LookupType(string qname)
internal static Type[] GetTypes(Assembly a)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a try-catch block here for transitive depedencies

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it an error, though, if we can't load transitive dependencies?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filmor i think it is someone else's job to load transitive dependencies, e.g. the direct dependencies should find them on their own:

NuGet/Home#6614

{
if (a.IsDynamic)
return a.GetTypes();
{
try
{
return a.GetTypes();
}
catch (ReflectionTypeLoadException exc)
{
// Return all types that were successfully loaded
return exc.Types.Where(x => x != null).ToArray();
}
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@denfromufa Is this what you had in mind?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filmor this is even more than what i asked for :)

else
return a.GetExportedTypes();
{
try
{
return a.GetExportedTypes();
}
catch (FileNotFoundException)
{
return new Type[0];
}
}
}
}
}
}