This documentation is archived and is not being maintained.

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)

'Declaration
<SerializableAttribute> _
Public Class InstallException _
	Inherits SystemException
'Usage
Dim instance As InstallException

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

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

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
Show: