@@ -39,14 +39,15 @@ public static IEnumerable<Assembly> GetAllReferencedAssemblies(MemberInfo member
3939 public static IEnumerable < Assembly > GetAllReferencedAssemblies ( MemberInfo memberInfo , HashSet < Assembly > holdingSet )
4040 {
4141 holdingSet . Clear ( ) ;
42+ var activeWorkingSet = new HashSet < Type > ( ) ;
4243
4344 if ( memberInfo is Type keyType )
4445 {
45- PopulateAllReferencedAssemblies ( keyType , holdingSet ) ;
46+ PopulateAllReferencedAssemblies ( keyType , activeWorkingSet , holdingSet ) ;
4647 }
4748 else if ( memberInfo . DeclaringType is Type declaredType )
4849 {
49- PopulateAllReferencedAssemblies ( declaredType , holdingSet ) ;
50+ PopulateAllReferencedAssemblies ( declaredType , activeWorkingSet , holdingSet ) ;
5051 }
5152
5253 return holdingSet ;
@@ -56,31 +57,33 @@ public static IEnumerable<Assembly> GetAllReferencedAssemblies(MemberInfo member
5657 /// Add to a provided <see cref="HashSet{T}"/> all assemblies referenced by a given type.
5758 /// </summary>
5859 /// <param name="inputType">The type to retrieve references for.</param>
60+ /// <param name="activeWorkingSet">A set to track types which have been processed.</param>
5961 /// <param name="holdingSet">A set to add any assemblies to.</param>
60- private static void PopulateAllReferencedAssemblies ( Type inputType , HashSet < Assembly > holdingSet )
62+ private static void PopulateAllReferencedAssemblies ( Type inputType , HashSet < Type > activeWorkingSet , HashSet < Assembly > holdingSet )
6163 {
6264 if ( inputType . IsArray && inputType . GetElementType ( ) is Type elementType )
6365 {
64- PopulateAllReferencedAssemblies ( elementType , holdingSet ) ;
66+ PopulateAllReferencedAssemblies ( elementType , activeWorkingSet , holdingSet ) ;
6567 }
6668
6769 var genericArguments = inputType . GenericTypeArguments ;
6870
6971 foreach ( var genericArgumentType in genericArguments )
7072 {
71- if ( holdingSet . Any ( a => a . DefinedTypes . Contains ( genericArgumentType ) ) )
73+ if ( activeWorkingSet . Contains ( genericArgumentType ) )
7274 {
7375 continue ;
7476 }
7577
76- PopulateAllReferencedAssemblies ( genericArgumentType , holdingSet ) ;
78+ PopulateAllReferencedAssemblies ( genericArgumentType , activeWorkingSet , holdingSet ) ;
7779 }
7880
7981 holdingSet . Add ( inputType . Assembly ) ;
82+ activeWorkingSet . Add ( inputType ) ;
8083
8184 if ( inputType . BaseType is not null && inputType . BaseType != typeof ( object ) )
8285 {
83- PopulateAllReferencedAssemblies ( inputType . BaseType , holdingSet ) ;
86+ PopulateAllReferencedAssemblies ( inputType . BaseType , activeWorkingSet , holdingSet ) ;
8487 }
8588 }
8689}
0 commit comments