public void UninstallAssembly(RegistrationConfig regConfig, object obSync)
        {
            CatalogSync        sync       = null;
            SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

            permission.Demand();
            permission.Assert();
            if (obSync != null)
            {
                if (!(obSync is CatalogSync))
                {
                    throw new ArgumentException(Resource.FormatString("Err_obSync"));
                }
                sync = (CatalogSync)obSync;
            }
            Assembly        asm  = this.NewLoadAssembly(regConfig.AssemblyFile);
            ApplicationSpec spec = new ApplicationSpec(asm, regConfig);

            if (spec.ConfigurableTypes != null)
            {
                this.PrepDriver(ref spec);
                if (spec.ConfigurableTypes != null)
                {
                    ICatalogObject obj2 = this.FindApplication(this._appColl, spec);
                    if (obj2 == null)
                    {
                        throw new RegistrationException(Resource.FormatString("Reg_AppNotFoundErr", spec));
                    }
                    ICatalogCollection collection = (ICatalogCollection)this._appColl.GetCollection(CollectionName.Components, obj2.Key());
                    string[]           arr        = new string[spec.ConfigurableTypes.Length];
                    int index = 0;
                    foreach (Type type in spec.ConfigurableTypes)
                    {
                        arr[index] = Marshal.GenerateGuidForType(type).ToString();
                        index++;
                    }
                    Populate(collection);
                    bool flag   = true;
                    int  lIndex = 0;
                    while (lIndex < collection.Count())
                    {
                        ICatalogObject obj3 = (ICatalogObject)collection.Item(lIndex);
                        string         g    = (string)obj3.Key();
                        g = new Guid(g).ToString();
                        if (this.FindIndexOf(arr, g) != -1)
                        {
                            collection.Remove(lIndex);
                            if (sync != null)
                            {
                                sync.Set();
                            }
                        }
                        else
                        {
                            lIndex++;
                            flag = false;
                        }
                    }
                    SaveChanges(collection);
                    if (flag)
                    {
                        for (int i = 0; i < this._appColl.Count(); i++)
                        {
                            ICatalogObject obj4 = (ICatalogObject)this._appColl.Item(i);
                            if (obj4.Key().Equals(obj2.Key()))
                            {
                                this._appColl.Remove(i);
                                if (sync != null)
                                {
                                    sync.Set();
                                }
                                break;
                            }
                        }
                        SaveChanges(this._appColl);
                    }
                }
                this.UnregisterAssembly(asm, spec);
                this.CleanupDriver();
            }
        }
        public void InstallAssembly(RegistrationConfig regConfig, object obSync)
        {
            Assembly           asm        = null;
            ApplicationSpec    spec       = null;
            CatalogSync        sync       = null;
            bool               flag       = false;
            bool               flag2      = false;
            SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

            try
            {
                permission.Demand();
                permission.Assert();
                ICatalogObject app = null;
                this.PrepArguments(regConfig);
                asm  = this.NewLoadAssembly(regConfig.AssemblyFile);
                spec = new ApplicationSpec(asm, regConfig);
                if (spec.ConfigurableTypes == null)
                {
                    regConfig.Application = null;
                    regConfig.TypeLibrary = null;
                }
                else
                {
                    if (obSync != null)
                    {
                        if (!(obSync is CatalogSync))
                        {
                            throw new ArgumentException(Resource.FormatString("Err_obSync"));
                        }
                        sync = (CatalogSync)obSync;
                    }
                    this.PrepDriver(ref spec);
                    string message = string.Empty;
                    if (!this.ValidateBitness(spec, out message))
                    {
                        throw new RegistrationException(message);
                    }
                    if ((regConfig.InstallationFlags & InstallationFlags.Register) != InstallationFlags.Default)
                    {
                        flag = !this.IsAssemblyRegistered(spec);
                        this.ClassicRegistration(spec.Assembly);
                        if ((regConfig.InstallationFlags & InstallationFlags.ExpectExistingTypeLib) != InstallationFlags.Default)
                        {
                            RegisterTypeLibrary(spec.TypeLib);
                        }
                        else
                        {
                            flag2 = true;
                            GenerateTypeLibrary(spec.Assembly, spec.TypeLib, new Report(this.ReportWarning));
                        }
                    }
                    if (((regConfig.InstallationFlags & InstallationFlags.Install) != InstallationFlags.Default) && (spec.ConfigurableTypes != null))
                    {
                        if ((regConfig.InstallationFlags & InstallationFlags.CreateTargetApplication) != InstallationFlags.Default)
                        {
                            app = this.CreateApplication(spec, true);
                        }
                        else if ((regConfig.InstallationFlags & InstallationFlags.FindOrCreateTargetApplication) != InstallationFlags.Default)
                        {
                            app = this.FindOrCreateApplication(spec, (regConfig.InstallationFlags & InstallationFlags.ReconfigureExistingApplication) != InstallationFlags.Default);
                        }
                        this.InstallTypeLibrary(spec);
                        if (sync != null)
                        {
                            sync.Set();
                        }
                    }
                    if (((regConfig.InstallationFlags & InstallationFlags.Configure) != InstallationFlags.Default) && (spec.ConfigurableTypes != null))
                    {
                        this.ConfigureComponents(spec);
                        if (sync != null)
                        {
                            sync.Set();
                        }
                    }
                    if (app != null)
                    {
                        this.PostProcessApplication(app, spec);
                    }
                    this.CleanupDriver();
                }
            }
            catch (Exception exception)
            {
                if ((exception is NullReferenceException) || (exception is SEHException))
                {
                    throw;
                }
                if (((exception is SecurityException) || (exception is UnauthorizedAccessException)) || ((exception.InnerException != null) && ((exception.InnerException is SecurityException) || (exception.InnerException is UnauthorizedAccessException))))
                {
                    exception = new RegistrationException(Resource.FormatString("Reg_Unauthorized"), exception);
                }
                if (flag && (null != asm))
                {
                    try
                    {
                        this.ClassicUnregistration(asm);
                    }
                    catch (Exception exception2)
                    {
                        if ((exception2 is NullReferenceException) || (exception2 is SEHException))
                        {
                            throw;
                        }
                    }
                }
                if (flag2 && (null != asm))
                {
                    try
                    {
                        this.UnregisterTypeLib(asm);
                    }
                    catch (Exception exception3)
                    {
                        if ((exception3 is NullReferenceException) || (exception3 is SEHException))
                        {
                            throw;
                        }
                    }
                }
                throw exception;
            }
        }