diff --git a/CHANGELOG.md b/CHANGELOG.md index e131c327b..e9ae801a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. ## [unreleased][] ### Added + - Added support for embedding python into dotnet core 2.0 (NetStandard 2.0) - Added new build system (pythonnet.15.sln) based on dotnetcore-sdk/xplat(crossplatform msbuild). Currently there two side-by-side build systems that produces the same output (net40) from the same sources. @@ -42,6 +43,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. - Fixed errors breaking .NET Remoting on method invoke ([#276][i276]) - Fixed PyObject.GetHashCode ([#676][i676]) - Fix memory leaks due to spurious handle incrementation ([#691][i691]) +- Fix spurious assembly loading exceptions from private types ([#703][i703]) - Fix inheritance of non-abstract base methods ([#755][i755]) diff --git a/src/runtime/assemblymanager.cs b/src/runtime/assemblymanager.cs index 2df7ad2f5..66c4b9904 100644 --- a/src/runtime/assemblymanager.cs +++ b/src/runtime/assemblymanager.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; using System.Threading; @@ -351,9 +352,7 @@ 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 = assembly.GetTypes(); - foreach (Type t in types) + foreach (Type t in GetTypes(assembly)) { string ns = t.Namespace ?? ""; if (!namespaces.ContainsKey(ns)) @@ -427,10 +426,9 @@ public static List GetNames(string nsname) { foreach (Assembly a in namespaces[nsname].Keys) { - Type[] types = a.GetTypes(); - foreach (Type t in types) + foreach (Type t in GetTypes(a)) { - if ((t.Namespace ?? "") == nsname) + if ((t.Namespace ?? "") == nsname && !t.IsNested) { names.Add(t.Name); } @@ -469,5 +467,32 @@ public static Type LookupType(string qname) } return null; } + + internal static Type[] GetTypes(Assembly a) + { + if (a.IsDynamic) + { + try + { + return a.GetTypes(); + } + catch (ReflectionTypeLoadException exc) + { + // Return all types that were successfully loaded + return exc.Types.Where(x => x != null).ToArray(); + } + } + else + { + try + { + return a.GetExportedTypes(); + } + catch (FileNotFoundException) + { + return new Type[0]; + } + } + } } -} +} \ No newline at end of file