Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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

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");
   }
}

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft