diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs index cee8abb23ab324..b799c50aeac5f2 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs @@ -33,5 +33,6 @@ public abstract class AssemblyBinder public abstract bool Bind(RuntimeAssemblyName refName, bool cacheMissedLookups, out AssemblyBindResult result, out Exception exception); public abstract IList GetLoadedAssemblies(); + public abstract int GetLoadedAssembliesCount(); } } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs index 2e0ba72727f33d..86d20bf94b2edb 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Assembly.NativeAot.cs @@ -35,13 +35,9 @@ public static Assembly Load(string assemblyString) } // Performance metric to count the number of assemblies - // Caching since in NativeAOT, the number will be the same - private static uint s_assemblyCount; internal static uint GetAssemblyCount() { - if (s_assemblyCount == 0) - s_assemblyCount = (uint)Internal.Reflection.Core.Execution.ReflectionCoreExecution.ExecutionEnvironment.AssemblyBinder.GetLoadedAssemblies().Count; - return s_assemblyCount; + return (uint)Internal.Reflection.Core.Execution.ReflectionCoreExecution.ExecutionEnvironment.AssemblyBinder.GetLoadedAssembliesCount(); } [Obsolete("Assembly.LoadWithPartialName has been deprecated. Use Assembly.Load() instead.")] diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Reflection/Execution/AssemblyBinderImplementation.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Reflection/Execution/AssemblyBinderImplementation.cs index fba014a2415992..43bda9d00fb01a 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Reflection/Execution/AssemblyBinderImplementation.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Reflection/Execution/AssemblyBinderImplementation.cs @@ -94,6 +94,11 @@ public sealed override IList GetLoadedAssemblies() return loadedAssemblies; } + public sealed override int GetLoadedAssembliesCount() + { + return ScopeGroups.Length; + } + // // Encapsulates the assembly ref->def matching policy. //