Esempio n. 1
0
        public static void UninstallAssembly(string displayName)
        {
            IAssemblyCache iac = null;

            CreateAssemblyCache(out iac, 0);
            try
            {
                uint whatHappened;
                int  hr = iac.UninstallAssembly(0, displayName, IntPtr.Zero, out whatHappened);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                switch (whatHappened)
                {
                case 2: throw new InvalidOperationException("Assembly still in use");

                case 5: throw new InvalidOperationException("Assembly still has install references");

                case 6: throw new System.IO.FileNotFoundException();        // Not actually raised
                }
            }
            finally
            {
                Marshal.FinalReleaseComObject(iac);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Uninstall the provided assembly names from the GAC. <paramref name="assemblyNames"/> have to be fully specified names. E.g., for v1.0/v1.1 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx". For v2.0+ assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx". If <paramref name="assemblyNames"/> is not fully specified, a random matching assembly could be uninstalled.
        /// </summary>
        /// <param name="assemblyNames"></param>
        /// <param name="reference"></param>
        /// <param name="disp"></param>
        public static void UninstallAssemblies(String[] assemblyNames, InstallReference reference, out AssemblyCacheUninstallDisposition[] disp)
        {
            AssemblyCacheUninstallDisposition dispResult = AssemblyCacheUninstallDisposition.Uninstalled;

            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            disp = new AssemblyCacheUninstallDisposition[assemblyNames.Length];
            int hr = Utils.CreateAssemblyCache(out ac, 0);

            if (hr >= 0)
            {
                for (var i = 0; i < assemblyNames.Length; i++)
                {
                    hr = ac.UninstallAssembly(0, assemblyNames[i], reference, out dispResult);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }

                    disp[i] = dispResult;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Remove an assembly with the given display name from the GAC
        /// </summary>
        /// <param name="displayName"></param>
        public static void UninstallAssembly(string displayName)
        {
            IAssemblyCache iac = null;

            CreateAssemblyCache(ref iac, 0);
            try
            {
                uint whatHappened = 0;
                int  hr           = iac.UninstallAssembly(0, displayName, IntPtr.Zero, ref whatHappened);
                if ((hr < 0))
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                switch ((whatHappened))
                {
                case 1: return;

                case 2: throw new InvalidOperationException("Assembly still in use");

                case 3: throw new InvalidOperationException("Already already uninstalled");

                case 5: throw new InvalidOperationException("Assembly still has install references");

                case 6: throw new System.IO.FileNotFoundException();     //Not actually raised?

                default: throw new InvalidOperationException("Unknown error: " + whatHappened);
                }
            }
            finally
            {
                Marshal.FinalReleaseComObject(iac);
            }
        }
Esempio n. 4
0
        // assemblyName has to be fully specified name.
        // A.k.a, for v1.0/v1.1 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx".
        // For v2.0 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx".
        // If assemblyName is not fully specified, a random matching assembly will be uninstalled.
        public static void UninstallAssembly(String assemblyName, FUSION_INSTALL_REFERENCE reference,
                                             out IASSEMBLYCACHE_UNINSTALL_DISPOSITION disp)
        {
            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);
            }

            //  Uninstall the assembly.
            hr = ac.UninstallAssembly(0, assemblyName, reference, out disp);
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }
 public void GacRemove(string AssemblyPath)
 {
     try
     {
         new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
         string         gacName        = new AssemblyManager().GetGacName(AssemblyPath);
         IAssemblyCache ppAsmCache     = null;
         int            num            = CreateAssemblyCache(out ppAsmCache, 0);
         uint           pulDisposition = 0;
         if (num == 0)
         {
             num = ppAsmCache.UninstallAssembly(0, gacName, IntPtr.Zero, out pulDisposition);
         }
         if (num != 0)
         {
             string str2 = Resource.FormatString("Soap_GacRemoveFailed");
             ComSoapPublishError.Report(str2 + " " + AssemblyPath + " " + gacName);
         }
     }
     catch (Exception exception)
     {
         if ((exception is NullReferenceException) || (exception is SEHException))
         {
             throw;
         }
         ComSoapPublishError.Report(exception.ToString());
         throw;
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Uninstalls the assembly.
        /// </summary>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="force">if set to <c>true</c> force.</param>
        /// <param name="result">The UninstallStatus result.</param>
        /// <returns>Returns <c>true</c> if uninstall successful.</returns>
        public static bool UninstallAssembly(string assemblyName, bool force, out UninstallStatus result)
        {
            result = UninstallStatus.None;

            string fullName;
            string fullPath = GetAssemblyPath(assemblyName, out fullName);

            if (string.IsNullOrEmpty(fullPath))
            {
                result = UninstallStatus.ReferenceNotFound;
                return(true);
            }

            IAssemblyCache cache = null;

            ThrowOnError(NativeMethods.CreateAssemblyCache(out cache, 0));

            int flags = force ? (int)CommitFlags.Force : (int)CommitFlags.Refresh;

            ThrowOnError(cache.UninstallAssembly(flags, fullName, null, out result));

            bool successful = false;

            switch (result)
            {
            case UninstallStatus.Uninstalled:
            case UninstallStatus.AlreadyUninstalled:
            case UninstallStatus.DeletePending:
                successful = true;
                break;
            }

            return(successful);
        }
Esempio n. 7
0
        // assemblyName has to be fully specified name.
        // A.k.a, for v1.0/v1.1 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx".
        // For v2.0 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx".
        // If assemblyName is not fully specified, a random matching assembly will be uninstalled.
        public static void UninstallAssembly(String assemblyName, InstallReference reference, out AssemblyCacheUninstallDisposition disp)
        {
            AssemblyCacheUninstallDisposition dispResult = AssemblyCacheUninstallDisposition.Uninstalled;

            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            int hr = Utils.CreateAssemblyCache(out ac, 0);

            if (hr >= 0)
            {
                hr = ac.UninstallAssembly(0, assemblyName, reference, out dispResult);
            }

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

            disp = dispResult;
        }
Esempio n. 8
0
        static internal int UninstallAssembly(string assembly)
        {
            assembly = System.Reflection.Assembly.LoadFrom(Path.GetFullPath(assembly)).FullName;
            uint           n;
            IAssemblyCache gac = null;
            int            hr  = CreateAssemblyCache(out gac, 0);

            return((hr != 0) ? hr : gac.UninstallAssembly(0, assembly, (IntPtr)0, out n));
        }
Esempio n. 9
0
        static public int RemoveAssemblyFromCache(string assemblyName)
        {
            IAssemblyCache ac = null;

            int hr = CreateAssemblyCache(out ac, 0);

            if (hr != 0)
            {
                return(hr);
            }

            uint n;

            return(ac.UninstallAssembly(0, assemblyName, (IntPtr)0, out n));
        }
Esempio n. 10
0
        static internal int RemoveAssemblyFromCache(string assembly)
        {
            IAssemblyCache ac = null;

            uint n;
            var  hr = CreateAssemblyCache(out ac, 0);

            if (hr != IntPtr.Zero)
            {
                return((int)hr);
            }
            else
            {
                return(ac.UninstallAssembly(0, assembly, (IntPtr)0, out n));
            }
        }
Esempio n. 11
0
        protected static void RemoveAssembly(string AssemblyName)
        {
            LogMessage("RemoveAssembly", "Uninstalling: " + AssemblyName);

            // Get an IAssemblyCache interface
            IAssemblyCache pCache = AssemblyCache.CreateAssemblyCache();

            IASSEMBLYCACHE_UNINSTALL_DISPOSITION puldisposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNKNOWN; // Initialise variable

            int result = pCache.UninstallAssembly(0, AssemblyName, null, out puldisposition);

            if (result == 0)
            {
                LogMessage("RemoveAssembly", "Uninstalled without error!");
            }
            else
            {
                LogMessage("RemoveAssembly", "Uninstall returned status code: " + result);
            }

            switch (puldisposition)
            {
            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED:
                LogMessage("RemoveAssembly", "Outcome: Assembly already uninstalled"); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_DELETE_PENDING:
                LogMessage("RemoveAssembly", "Outcome: Delete currently pending"); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_HAS_INSTALL_REFERENCES:
                LogMessage("RemoveAssembly", "Outcome: Assembly has remaining install references"); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_REFERENCE_NOT_FOUND:
                LogMessage("RemoveAssembly", "Outcome: Unable to find assembly - " + AssemblyName); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_STILL_IN_USE:
                LogMessage("RemoveAssembly", "Outcome: Assembly still in use"); break;

            case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED:
                LogMessage("RemoveAssembly", "Outcome: Assembly uninstalled"); break;

            default:
                LogMessage("RemoveAssembly", "Unknown uninstall outcome code: " + puldisposition); break;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Uninstalls the assembly, using the application as a reference.
        /// AssemblyName has to be fully specified name.
        /// A.k.a, for v1.0/v1.1 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx".
        /// For v2.0 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx".
        /// If assemblyName is not fully specified, a random matching assembly will be uninstalled.
        /// </summary>
        /// <param name="assemblyName"></param>
        private static AssemblyCacheUninstallDisposition UninstallAssemblyImplementation(String assemblyName)
        {
            AssemblyCacheUninstallDisposition dispResult = AssemblyCacheUninstallDisposition.Uninstalled;
            IAssemblyCache ac = null;

            int hr = GacUtils.CreateAssemblyCache(out ac, 0);

            if (hr >= 0)
            {
                hr = ac.UninstallAssembly(0, assemblyName, null, out dispResult);
            }

            if (hr < 0)
            {
                GacUtils.ThrowMarshalledException(hr);
            }

            return(dispResult);
        }
Esempio n. 13
0
        public static void UninstallAssembly(string assemblyName, InstallReference reference, out AssemblyCacheUninstallDisposition disp)
        {
            AssemblyCacheUninstallDisposition dispResult = AssemblyCacheUninstallDisposition.Uninstalled;

            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid argument (reference guid).");
                }
            }

            IAssemblyCache asmCache = null;

            COM.CheckHR(CreateAssemblyCache(out asmCache, 0));
            COM.CheckHR(asmCache.UninstallAssembly(0, assemblyName, reference, out dispResult));

            disp = dispResult;
        }
Esempio n. 14
0
        public bool GacUnInstall(string assemblyName)
        {
            IAssemblyCache ppAsmCache     = null;
            uint           pulDisposition = 0;
            int            num2           = NativeMethods.CreateAssemblyCache(out ppAsmCache, 0);

            if (num2 == 0)
            {
                num2 = ppAsmCache.UninstallAssembly(0, assemblyName, IntPtr.Zero, out pulDisposition);
                if (pulDisposition == 3)
                {
                    return(false);
                }
            }
            if (num2 != 0)
            {
                throw new Exception(System.Web.SR.GetString("Failed_gac_uninstall"));
            }
            return(true);
        }
Esempio n. 15
0
        public bool GacUnInstall(string assemblyName)
        {
            IAssemblyCache ac       = null;
            uint           position = 0;
            int            hr       = NativeMethods.CreateAssemblyCache(out ac, 0);

            if (0 == hr)
            {
                hr = ac.UninstallAssembly(0, assemblyName, IntPtr.Zero, out position);
                if (position == 3 /*IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED*/)
                {
                    return(false);
                }
            }

            if (0 != hr)
            {
                throw new Exception(SR.GetString(SR.Failed_gac_uninstall));
            }

            return(true);
        }
        }// AddAssemblyToGac

        internal static bool RemoveAssemblyFromGac(AssemInfo aInfo)
        {
            IAssemblyCache ac = null;
            int            hr = CreateAssemblyCache(out ac, 0);
            uint           n;

            if (aInfo.sCustom.Length > 0)
            {
                // We need to take this string, byte-ify it, then string-ify it.
                // Why?
                // We need our string:
                // ZAP........
                // to be
                // 900041005000.......
                aInfo.sFusionName += ",Custom=" + ByteArrayToString(StringToByteArray(aInfo.sCustom));
            }

            int nRet = ac.UninstallAssembly(0, aInfo.sFusionName, (IntPtr)0, out n);

            if (nRet != HRESULT.S_OK)
            {
                // Ok, something kind of funky happened.... let's see if this item really did get removed from the cache
                ArrayList al = new ArrayList();
                ReadCache(al, aInfo.nCacheType);

                // See if our item is in here.....
                for (int i = 0; i < al.Count; i++)
                {
                    AssemInfo ai = (AssemInfo)al[i];
                    if (ai.Name.Equals(aInfo.Name) && ai.PublicKeyToken.Equals(aInfo.PublicKeyToken) && ai.Version.Equals(aInfo.Version))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }// RemoveAssemblyFromGac
Esempio n. 17
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine(" tgacutil {/i|/u} Assembly [Assembly]...");
                Console.WriteLine(" /i : Install assemblies into GAC. Specify assemblies by full-path.");
                Console.WriteLine(" /u : Uninstall assemblies from GAC. Specify assemblies by assembly name.");
                return;
            }

            string mode = args[0].ToLower();

            string[] assemblies = args.Skip(1).ToArray();

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

            foreach (string assembly in assemblies)
            {
                if (mode == "/i")
                {
                    hr = ac.InstallAssembly(0, assembly, null);
                    if (hr == 0)
                    {
                        Console.WriteLine(string.Format("{0}: Installed", System.IO.Path.GetFileNameWithoutExtension(assembly)));
                    }
                }
                else if (mode == "/u")
                {
                    UninstallStatus result = 0;
                    ac.UninstallAssembly(0, assembly, null, out result);
                    Console.WriteLine(string.Format("{0}: {1}", Path.GetFileNameWithoutExtension(assembly), result.ToString()));
                }
            }
        }
Esempio n. 18
0
        static int Main(string[] args)
        {
            // Process arguments

            bool   install  = true; // Initialise variables
            string filename = "";
            bool   help     = false;
            bool   versions = false;
            bool   list     = false;

            if (args.Length == 0)
            {
                help = true;      // No arguments will print a help message
            }
            if (args.Length == 1) // One argument could be /H /V or /L a filename
            {
                if (string.Compare(args[0], "/H", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    help = true;                                                                         // Test for help switch
                }
                if (string.Compare(args[0], "-H", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    help = true;
                }
                if (string.Compare(args[0], "/V", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    versions = true;                                                                         // Test for help switch
                }
                if (string.Compare(args[0], "-V", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    versions = true;
                }
                if (string.Compare(args[0], "/L", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    list = true;                                                                         // Test for list switch
                }
                if (string.Compare(args[0], "-L", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    list = true;
                }
                filename = args[0];
            }

            if (args.Length == 2)
            {
                if (string.Compare(args[0], "/H", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    help = true;                                                                         // Test for help switch
                }
                if (string.Compare(args[0], "-H", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    help = true;
                }
                if (string.Compare(args[1], "/H", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    help = true;
                }
                if (string.Compare(args[1], "-H", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    help = true;
                }

                if ((string.Compare(args[0], "/U", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(args[0], "-U", StringComparison.OrdinalIgnoreCase) == 0))
                {                       // Found uninstall switch in first argument
                    install  = false;
                    filename = args[1]; // Filename must be second argument
                }
                else
                {
                    filename = args[0]; // Filename must be first argument
                    if ((string.Compare(args[1], "/U", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(args[1], "-U", StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        install = false; // Uninstall switch found as second argument
                    }
                }
            }

            // help, versions, install and filename now contain the supplied parameters
            if (help)
            {
                // Help requested so print message
                Console.WriteLine("GACInstall adds and removes assemblies from the cache");
                Console.WriteLine("");
                Console.WriteLine("Usage: GACInstall AssemblyFileName");
                Console.WriteLine("       GACInstall /U AssemblyName");
                return(0);
            }

            if (versions)
            {
                // versions requested so list the required information
                Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().FullName);
                Console.WriteLine(System.IO.Directory.Exists("fusion.dll"));
                Console.WriteLine(System.IO.Directory.GetCurrentDirectory());
                Console.WriteLine("Full path to fusion.dll: " + System.IO.Path.GetFullPath("fusion.dll") + "#");
                Console.WriteLine("Path: " + System.Environment.GetEnvironmentVariable("PATH"));
                return(0);
            }

            if (list)
            {
                // List ASCOM assemblies
                SortedList <String, String> assemblyNames = new SortedList <String, String>();
                IAssemblyEnum assemblyEnumerator          = AssemblyCache.CreateGACEnum(); // Get an enumerator for the GAC assemblies
                IAssemblyName iAssemblyName = null;

                while ((AssemblyCache.GetNextAssembly(assemblyEnumerator, out iAssemblyName) == 0))
                {
                    try
                    {
                        AssemblyName assemblyName = new AssemblyName();
                        try
                        {
                            assemblyName.Name        = AssemblyCache.GetName(iAssemblyName);
                            assemblyName.Version     = AssemblyCache.GetVersion(iAssemblyName);
                            assemblyName.CultureInfo = AssemblyCache.GetCulture(iAssemblyName);
                            assemblyName.SetPublicKeyToken(AssemblyCache.GetPublicKeyToken(iAssemblyName));
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("GetAssemblyName Exception: " + ex.ToString());
                        }

                        assemblyNames.Add(assemblyName.FullName, assemblyName.Name);
                    }
                    catch
                    {
                        // Ignore an exceptions here due to duplicate names, these are all MS assemblies
                    }
                }

                Console.WriteLine("\r\nInstalled ASCOM assemblies: ");

                foreach (KeyValuePair <string, string> assemblyName in assemblyNames)
                {
                    //  Process each assembly in turn
                    try
                    {
                        if (((assemblyName.Key.IndexOf("ASCOM", StringComparison.OrdinalIgnoreCase) + 1) > 0) || (assemblyName.Key.Contains("565de7938946fba7")))
                        {
                            Console.WriteLine(assemblyName.Key);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("AssemblyName.Key Exception: " + ex.ToString());
                    }
                }
                return(0);
            }

            // Must be install or uninstall
            int result = 0; // Initialise return code to OK

            // Create an FUSION_INSTALL_REFERENCE struct and fill it with data
            // We use opaque scheme here
            FUSION_INSTALL_REFERENCE[] installReference = new FUSION_INSTALL_REFERENCE[1];
            installReference[0].dwFlags             = 0;
            installReference[0].guidScheme          = AssemblyCache.FUSION_REFCOUNT_OPAQUE_STRING_GUID;
            installReference[0].szIdentifier        = "GACInstall";
            installReference[0].szNonCannonicalData = "Installed by ASCOM's GACInstall program";
            installReference[0].cbSize = 40;

            // Get an IAssemblyCache interface
            IAssemblyCache pCache = AssemblyCache.CreateAssemblyCache();

            if (install)
            { // We are going to install an assembly
                try
                {
                    if (System.IO.File.Exists(filename))
                    {
                        result = pCache.InstallAssembly(0, filename, null);
                        if (result == 0)
                        {
                            Console.WriteLine("Installed OK!");
                        }
                        else
                        {
                            Console.WriteLine("Install returned error code: " + result);
                        }
                        return(result);
                    }
                    else
                    {
                        Console.WriteLine("Unable to find file: " + filename);
                        return(1);
                    }
                }
                catch (Exception ex)
                {
                    result = 2;
                    Console.WriteLine("Exception: " + ex.ToString());
                    return(result);
                }
            }
            else // We are going to uninstall an assembly
            {
                try
                {
                    {                                                                                                                                            // We are going to uninstall an assembly
                        IASSEMBLYCACHE_UNINSTALL_DISPOSITION puldisposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNKNOWN; // Initialise variable
                        result = pCache.UninstallAssembly(0, filename, null, out puldisposition);
                        if (result == 0)
                        {
                            Console.WriteLine("Uninstalled with no error!");
                        }
                        else
                        {
                            Console.WriteLine("Uninstall returned error code: " + result);
                        }

                        switch (puldisposition)
                        {
                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED:
                            Console.WriteLine("Outcome: Assembly already uninstalled"); break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_DELETE_PENDING:
                            Console.WriteLine("Outcome: Delete currently pending"); break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_HAS_INSTALL_REFERENCES:
                            Console.WriteLine("Outcome: Assembly has remaining install references"); break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_REFERENCE_NOT_FOUND:
                            Console.WriteLine("Outcome: Unable to find assembly - " + filename); break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_STILL_IN_USE:
                            Console.WriteLine("Outcome: Assembly still in use"); break;

                        case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED:
                            Console.WriteLine("Outcome: Assembly uninstalled"); break;

                        default:
                            Console.WriteLine("Unknown uninstall outcome code: " + puldisposition); break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = 2;
                    Console.WriteLine("Exception: " + ex.ToString());
                }

                return(result);
            }
        }