Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

InstallException Class

The exception that is thrown when an error occurs during the commit, rollback, or uninstall phase of an installation.

Namespace: System.Configuration.Install
Assembly: System.Configuration.Install (in system.configuration.install.dll)

[SerializableAttribute] 
public class InstallException : SystemException
/** @attribute SerializableAttribute() */ 
public class InstallException extends SystemException
SerializableAttribute 
public class InstallException extends SystemException

The following example, plus the examples in the InstallException constructors, together make up an example showing an assembly having its own installer. The installer is named MyInstaller, which has an attribute RunInstallerAttribute, indicating that this installer will be invoked by Installer Tool (Installutil.exe). Installer Tool (Installutil.exe) calls the methods Commit, Rollback, Install and Uninstall. The code in Commit presumes that a file named FileDoesNotExist.txt exists before the installation of the assembly can be committed. If the file FileDoesNotExist.txt does not exist, Commit raises an InstallException. The same is the case with Uninstall in which an uninstallation will only happen if a file named FileDoesNotExist.txt exists. Otherwise it raises an InstallException. In Rollback, a code fragment is executed, which might raise an exception. If the exception is raised, it is caught and an InstallException is raised with that exception being passed to it.

NoteNote

Run this example with the help of Installutil.exe. Type this in the command prompt:

Installutil InstallException.exe

-or-

Installutil /u InstallException.exe

using System;
using System.ComponentModel;
using System.Collections;
using System.Configuration.Install;
using System.IO;


[RunInstaller(true)]
public class MyInstaller : Installer
{
   public override void Install(IDictionary savedState)
   {
      base.Install(savedState);
      Console.WriteLine("Install ...");

      // Commit is called when install goes through successfully.
      // Rollback is called if there is any error during Install.

      // Uncommenting the code below will lead to 'RollBack' being called,
      // currently 'Commit' shall be called.

      // throw new IOException();
   

   public override void Commit(IDictionary savedState)
   {
      base.Commit(savedState);
      Console.WriteLine("Commit ...");
      // Throw an error if a particular file doesn't exist.
      if(!File.Exists("FileDoesNotExist.txt"))
         throw new InstallException();
      // Perform the final installation if the file exists.
   

   public override void Rollback(IDictionary savedState)
   {
      base.Rollback(savedState);
      Console.WriteLine("RollBack ...");
      try
      {
         // Performing some activity during rollback that raises an 'IOException'.
         throw new IOException();
      
      catch(Exception e)
      {
         throw new InstallException("IOException raised", e);
      
      // Perform the remaining rollback activites if no exception raised.
   

   public override void Uninstall(IDictionary savedState)
   {
      base.Uninstall(savedState);
      Console.WriteLine("UnInstall ...");
      // Throw an error if a particular file doesn't exist.
      if(!File.Exists("FileDoesNotExist.txt"))
         throw new InstallException("The file 'FileDoesNotExist'" +
            " does not exist");
      // Perform the uninstall activites if the file exists.
   



// An Assembly that has its own installer.
public class MyAssembly1
{
   public static void Main()
   {
      Console.WriteLine("This assembly is just an example for the Installer");
   


import System.*;
import System.ComponentModel.*;
import System.Collections.*;
import System.Configuration.Install.*;
import System.IO.*;

/** @attribute RunInstaller(true)
 */
public class MyInstaller extends Installer
{
    public void Install(IDictionary savedState)
    {
        super.Install(savedState);
        Console.WriteLine("Install ...");
     //Install

    // Commit is called when install goes through successfully.
    // Rollback is called if there is any error during Install.
    // Uncommenting the code below will lead to 'RollBack' being called,
    // currently 'Commit' shall be called.
    // throw new IOException();
    public void Commit(IDictionary savedState) 
        throws System.Configuration.Install.InstallException   
    {
        super.Commit(savedState);
        Console.WriteLine("Commit ...");

        // Throw an error if a particular file doesn't exist.
        if (!(File.Exists("FileDoesNotExist.txt"))) {
            throw new InstallException();
        
        // Perform the final installation if the file exists.
     //Commit
    public void Rollback(IDictionary savedState) 
        throws System.Configuration.Install.InstallException   
    {
        super.Rollback(savedState);
        Console.WriteLine("RollBack ...");
        try {
            // Performing some activity during rollback 
            //that raises an 'IOException'.
            throw new IOException();
        
        catch (System.Exception e) {
            throw new InstallException("IOException raised", e);
        
        // Perform the remaining rollback activites if no exception raised.
     //Rollback
    public void Uninstall(IDictionary savedState) 
        throws System.Configuration.Install.InstallException   
    {
        super.Uninstall(savedState);
        Console.WriteLine("UnInstall ...");

        // Throw an error if a particular file doesn't exist.
        if (!(File.Exists("FileDoesNotExist.txt"))) {
            throw new InstallException("The file 'FileDoesNotExist'" 
                + " does not exist");
        
     //Uninstall
 //MyInstaller
 // Perform the uninstall activites if the file exists.

// An Assembly that has its own installer.
public class MyAssembly1
{
    public static void main(String[] args)
    {
        Console.WriteLine("This assembly is just an example for the Installer");
     //main
 //MyAssembly1

System.Object
   System.Exception
     System.SystemException
      System.Configuration.Install.InstallException
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.