Exemplo n.º 1
0
        /// <summary>
        /// Gets the names of all assemblies in the GAC.
        /// </summary>
        public static IEnumerable <AssemblyNameInfo> GetGacAssemblyFullNames()
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0);
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder name = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(name, ref nChars, 0);

                AssemblyNameInfo r = null;
                try {
                    r = new AssemblyNameInfo(name.ToString());
                } catch (ArgumentException) {
                } catch (FormatException) {
                } catch (OverflowException) {
                }
                if (r != null)
                {
                    yield return(r);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the names of all assemblies in the GAC.
        /// </summary>
        public static IEnumerable <AssemblyNameInfo> GetGacAssemblyFullNames()
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0);
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder name = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(name, ref nChars, 0);

                var r = new AssemblyNameInfo(name.ToString());
                if (r.Version != null)
                {
                    yield return(r);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the names of all assemblies in the GAC.
        /// </summary>
        public static IEnumerable <AssemblyNameReference> GetGacAssemblyFullNames()
        {
            IApplicationContext applicationContext = null;
            IAssemblyEnum       assemblyEnum       = null;
            IAssemblyName       assemblyName       = null;

            uint result = unchecked ((uint)Fusion.CreateAssemblyEnum(out assemblyEnum, null, null, 2, 0));

            if (result == 0x80070005)
            {
                MessageBox.Show($"Cannot access GAC, please restart with elevated privileges! (HRESULT 0x{result:X})", "ILSpy", MessageBoxButton.OK, MessageBoxImage.Error);
                yield break;
            }
            while (assemblyEnum.GetNextAssembly(out applicationContext, out assemblyName, 0) == 0)
            {
                if (assemblyName == null)
                {
                    continue;
                }
                uint nChars = 0;
                assemblyName.GetDisplayName(null, ref nChars, 0);

                StringBuilder name = new StringBuilder((int)nChars);
                assemblyName.GetDisplayName(name, ref nChars, 0);

                AssemblyNameReference r = null;
                try {
                    r = AssemblyNameReference.Parse(name.ToString());
                } catch (ArgumentException) {
                } catch (FormatException) {
                } catch (OverflowException) {
                }
                if (r != null)
                {
                    yield return(r);
                }
            }
        }