-
Notifications
You must be signed in to change notification settings - Fork 749
Optimizes implicit assembly loading. Helps to reduce amount of faulted LoadAssembly calls. #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8ee0c65
d09fc92
4af13a3
c28bafd
f016059
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,8 +203,10 @@ public static Assembly LoadAssembly(string name) | |
} | ||
|
||
PythonEngine.RaiseAssemblyAsModuleImportingEvent(importEvent); | ||
|
||
assembly = Assembly.Load(name); | ||
if (!importEvent.SkipAssemblyLoad) | ||
{ | ||
assembly = Assembly.Load(name); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
|
@@ -351,8 +353,17 @@ internal static void ScanAssembly(Assembly assembly) | |
// A couple of things we want to do here: first, we want to | ||
// gather a list of all of the namespaces contributed to by | ||
// the assembly. | ||
Type[] types = new Type[0]; | ||
try | ||
{ | ||
types = assembly.IsDynamic ? assembly.GetTypes():assembly.GetExportedTypes(); | ||
} | ||
catch(TypeLoadException) | ||
{ | ||
// Do nothing. | ||
// This problem usually occurs when transitive dependencies have references to older packages than main application. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmitriyse what do you mean by transitive dependencies? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may be wrong, but ReflectionTypeLoadException is thrown by GetTypes() if any of the dependent assemblies can't be loaded (with a list of the loaded types), but GetExportedTypes() throws FileNotFoundException with no information. I'm not sure if TypeLoadException is thrown here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Cronan i think you are right about TypeLoadException -> ReflectionTypeLoadException, these are 2 different exceptions and I believe this was a typo from @dmitriyse: https://msdn.microsoft.com/en-us/library/system.typeloadexception(v=vs.110).aspx |
||
} | ||
|
||
Type[] types = assembly.GetTypes(); | ||
foreach (Type t in types) | ||
{ | ||
string ns = t.Namespace ?? ""; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmitriyse can you please add explanation for why you added check for
isDynamic
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should there be a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the documentation, GetExportedTypes() is not supported on dynamic types and will throw NotSupportedException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cronan good explanation! still maybe worth adding a comment about this. especially explaining the switch from GetTypes to GetExportedTypes for normal types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmitriyse @Cronan ok, I see this comment in the header of the PR:
Assembly.GetTypes replaced to Assembly.GetExportedTypes. So we are really skipping non-public types now.
Type.IsNested types are excluded from the names collection that is used for implicit assembly loading.