// Internal for testing. internal static IEnumerable <FusionAssemblyIdentity.IAssemblyName> GetAssemblyObjects( FusionAssemblyIdentity.IAssemblyName partialNameFilter, ProcessorArchitecture[] architectureFilter) { IAssemblyEnum enumerator; int hr = CreateAssemblyEnum(out enumerator, null, partialNameFilter, ASM_CACHE.GAC, IntPtr.Zero); if (hr == S_FALSE) { // no assembly found yield break; } if (hr != S_OK) { Exception e = Marshal.GetExceptionForHR(hr); if (e is FileNotFoundException) { // invalid assembly name: yield break; } if (e != null) { throw e; } // for some reason it might happen that CreateAssemblyEnum returns non-zero HR that doesn't correspond to any exception: throw new ArgumentException("Invalid assembly name"); } while (true) { FusionAssemblyIdentity.IAssemblyName nameObject; FusionAssemblyIdentity.IApplicationContext applicationContext; hr = enumerator.GetNextAssembly(out applicationContext, out nameObject, 0); if (hr != 0) { if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } break; } if (architectureFilter != null) { var assemblyArchitecture = FusionAssemblyIdentity.GetProcessorArchitecture(nameObject); if (!architectureFilter.Contains(assemblyArchitecture)) { continue; } } yield return(nameObject); } }