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.

For a list of all members of this type, see InstallException Members.

System.Object
   System.Exception
      System.SystemException
         System.Configuration.Install.InstallException

[Visual Basic]
<Serializable>
Public Class InstallException
   Inherits SystemException
[C#]
[Serializable]
public class InstallException : SystemException
[C++]
[Serializable]
public __gc class InstallException : public SystemException
[JScript]
public
   Serializable
class InstallException extends SystemException

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic, C#, C++] Note   Run this example with the help of Installutil.exe. Type this in the command prompt:

[Visual Basic, C#, C++] Installutil InstallException.exe

[Visual Basic, C#, C++]-or-

[Visual Basic, C#, C++] Installutil /u InstallException.exe

[Visual Basic] 
Imports System
Imports System.ComponentModel
Imports System.Collections
Imports System.Configuration.Install
Imports System.IO

<RunInstaller(True)> Public Class MyInstaller
   Inherits Installer

   Public Overrides Sub Install(savedState As IDictionary)
      MyBase.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();

   End Sub

   Public Overrides Sub Commit(savedState As IDictionary)
      MyBase.Commit(savedState)
      Console.WriteLine("Commit ...")
      ' Throw an error if a particular file doesn't exist.
      If Not File.Exists("FileDoesNotExist.txt") Then
         Throw New InstallException()
      End If
      ' Perform the final installation if the file exists.
   End Sub

   Public Overrides Sub Rollback(savedState As IDictionary)
      MyBase.Rollback(savedState)
      Console.WriteLine("RollBack ...")
      Try
         ' Performing some activity during rollback that raises an 'IOException'.
         Throw New IOException()
      Catch e As Exception
         Throw New InstallException("IOException raised", e)
      End Try
   End Sub 'Rollback
    ' Perform the remaining rollback activites if no exception raised.

   Public Overrides Sub Uninstall(savedState As IDictionary)
      MyBase.Uninstall(savedState)
      Console.WriteLine("UnInstall ...")
      ' Throw an error if a particular file doesn't exist.
      If Not File.Exists("FileDoesNotExist.txt") Then
         Throw New InstallException("The file 'FileDoesNotExist'" + " does not exist")
      End If
      ' Perform the uninstall activites if the file exists.
   End Sub

End Class

' An Assembly that has its own installer.
Public Class MyAssembly1
   Public Shared Sub Main()
      Console.WriteLine("This assembly is just an example for the Installer")
   End Sub
End Class

[C#] 
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");
   }
}

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Configuration::Install;
using namespace System::IO;

[RunInstaller(true)]
__gc class MyInstaller : public Installer {
public:
    void Install(IDictionary* savedState) {
        Installer::Install(savedState);
        Console::WriteLine(S"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();
    }

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

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

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

int main() {
    Console::WriteLine(S"This assembly is just an example for the Installer");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Configuration.Install

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Configuration.Install (in System.Configuration.Install.dll)

See Also

InstallException Members | System.Configuration.Install Namespace | Commit | Installer | Rollback | Uninstall

Show:
© 2015 Microsoft