public static IAssemblyCache GetIAssemblyCache(String assemblyName, FUSION_INSTALL_REFERENCE reference)
        {
            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidUninstallGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            //  Create an assembly cache objet.
            IAssemblyCache ac = null;
            int            hr = FusionImports.CreateAssemblyCache(out ac, 0);

            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            return(ac);

            //////////  Uninstall the assembly.
            ////////hr = ac.UninstallAssembly(0, assemblyName, reference, out disp);
            ////////if (hr < 0)
            ////////    Marshal.ThrowExceptionForHR(hr);
        }
        public static void InstallAssembly(String assemblyPath, FUSION_INSTALL_REFERENCE reference, AssemblyCommitFlags flags)
        {
            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidInstallGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            int hr = 0;

            hr = FusionImports.CreateAssemblyCache(out ac, 0);
            if (hr >= 0)
            {
                hr = ac.InstallAssembly((int)flags, assemblyPath, reference);
            }

            if (hr < 0)
            {
                if (hr == -2146234300 /*0x80131044*/)
                {
                    throw new AssemblyMustBeStronglyNamedException();
                }
                else
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
        }
        // See comments in UninstallAssembly
        public static String QueryAssemblyInfo(String assemblyName)
        {
            if (assemblyName == null)
            {
                throw new ArgumentException("Invalid name", "assemblyName");
            }

            var aInfo = new ASSEMBLY_INFO();

            aInfo.cchBuf = 1024;
            // Get a string with the desired length
            aInfo.currentAssemblyPath = new String('\0', aInfo.cchBuf);

            IAssemblyCache ac = null;
            int            hr = FusionImports.CreateAssemblyCache(out ac, 0);

            if (hr >= 0)
            {
                hr = ac.QueryAssemblyInfo(0, assemblyName, ref aInfo);
            }
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            return(aInfo.currentAssemblyPath);
        }
        private void Initialise(string assemblyName)
        {
            IAssemblyName fusionName = null;
            int           hr;

            //  If we have an assembly name, create the assembly name object.
            if (assemblyName != null)
            {
                hr = FusionImports.CreateAssemblyNameObject(out fusionName, assemblyName,
                                                            CREATE_ASM_NAME_OBJ_FLAGS.CANOF_PARSE_DISPLAY_NAME, IntPtr.Zero);

                //  Check the result.
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            //  Create the assembly enumerator.
            hr = FusionImports.CreateAssemblyEnum(out assemblyEnumerator, IntPtr.Zero,
                                                  fusionName, ASM_CACHE_FLAGS.ASM_CACHE_GAC, IntPtr.Zero);

            //  Check the result.
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }
        public InstallReferenceEnumerator(IAssemblyName assemblyName)
        {
            var hr = FusionImports.CreateInstallReferenceEnum(out _refEnum, assemblyName, 0, IntPtr.Zero);

            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }
        public InstallReferenceEnumerator(String assemblyName)
        {
            IAssemblyName fusionName = null;

            int hr = FusionImports.CreateAssemblyNameObject(
                out fusionName,
                assemblyName,
                CREATE_ASM_NAME_OBJ_FLAGS.CANOF_PARSE_DISPLAY_NAME,
                IntPtr.Zero);

            if (hr >= 0)
            {
                hr = FusionImports.CreateInstallReferenceEnum(out _refEnum, fusionName, 0, IntPtr.Zero);
            }

            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }