public void Refresh()
                {
                    if (_refs == null)
                    {
                        _refs = new ArrayList();
                    }
                    else
                    {
                        _refs.Clear();
                    }

                    Fusion.IInstallReferenceEnum refEnum;

                    ComUtil.ComCheck(Fusion.CreateInstallReferenceEnum(out refEnum, _name._name, 0, IntPtr.Zero));

                    Fusion.IInstallReferenceItem item;

                    while (ComUtil.SUCCEEDED(refEnum.GetNextInstallReferenceItem(out item, 0, IntPtr.Zero)) && item != null)
                    {
                        IntPtr pRef;

                        ComUtil.ComCheck(item.GetReference(out pRef, 0, IntPtr.Zero));

                        Fusion.FUSION_INSTALL_REFERENCE objRef = (Fusion.FUSION_INSTALL_REFERENCE)
                                                                 Marshal.PtrToStructure(pRef, typeof(Fusion.FUSION_INSTALL_REFERENCE));

                        _refs.Add(new InstallReference(objRef));
                    }
                }
        public void Install(string fileName, IntPtr pRef)
        {
            IAssemblyCache cache;

            ComUtil.ComCheck(Fusion.CreateAssemblyCache(out cache, 0));

            ComUtil.ComCheck(cache.InstallAssembly(Fusion.ASM_INSTALL_FLAG.IASSEMBLYCACHE_INSTALL_FLAG_REFRESH, fileName, pRef));
        }
        public UninstallDisposition Uninstall(string assemblyName, IntPtr pRef)
        {
            IAssemblyCache cache;

            ComUtil.ComCheck(Fusion.CreateAssemblyCache(out cache, 0));

            ASM_UNINSTALL_DISPOSITION disposition;

            ComUtil.ComCheck(cache.UninstallAssembly(0, assemblyName, pRef, out disposition));

            return((UninstallDisposition)disposition);
        }
        public static string GetCachePath(ASM_CACHE_FLAGS cache)
        {
            uint len = 0;

            int hr = Fusion.GetCachePath(cache, null, ref len);

            if (hr == ComUtil.ERROR_INSUFFICIENT_BUFFER && len > 0)
            {
                StringBuilder sb = new StringBuilder((int)len);

                ComUtil.ComCheck(Fusion.GetCachePath(cache, sb, ref len));

                return(sb.ToString());
            }
            else
            {
                return("");
            }
        }
        public bool Check(string assemblyName, out string msg)
        {
            IAssemblyCache cache;

            ComUtil.ComCheck(Fusion.CreateAssemblyCache(out cache, 0));

            ASSEMBLY_INFO info = new ASSEMBLY_INFO();

            info.cbAssemblyInfo            = (uint)Marshal.SizeOf(info);
            info.cchBuf                    = 0;
            info.pszCurrentAssemblyPathBuf = IntPtr.Zero;

            int hr = cache.QueryAssemblyInfo(QUERYASMINFO_FLAG.QUERYASMINFO_FLAG_VALIDATE, assemblyName, ref info);

            if (hr == ComUtil.ERROR_INSUFFICIENT_BUFFER && info.cchBuf > 0)
            {
                info.pszCurrentAssemblyPathBuf = Marshal.AllocCoTaskMem((int)info.cchBuf * 2);
                try
                {
                    ComUtil.ComCheck(cache.QueryAssemblyInfo(
                                         QUERYASMINFO_FLAG.QUERYASMINFO_FLAG_VALIDATE | QUERYASMINFO_FLAG.QUERYASMINFO_FLAG_GETSIZE,
                                         assemblyName, ref info));

                    string path = Marshal.PtrToStringUni(info.pszCurrentAssemblyPathBuf);

                    msg = string.Format("{0} ({1} KB) @ {2}", assemblyName, info.uliAssemblySizeInKB, path);
                }
                finally
                {
                    Marshal.FreeCoTaskMem(info.pszCurrentAssemblyPathBuf);
                }

                return(true);
            }
            else
            {
                try { Marshal.ThrowExceptionForHR(hr); msg = ""; }
                catch (Exception e) { msg = e.Message; }

                return(false);
            }
        }