InstallException Clase

Definición

Excepción que se produce cuando se genera un error durante la fase en la que se confirma, se revierte o se desinstala una instalación.The exception that is thrown when an error occurs during the commit, rollback, or uninstall phase of an installation.

public ref class InstallException : SystemException
[System.Serializable]
public class InstallException : SystemException
type InstallException = class
    inherit SystemException
Public Class InstallException
Inherits SystemException
Herencia
InstallException
Atributos

Ejemplos

En el ejemplo siguiente, además de los ejemplos InstallException de los constructores, forman un ejemplo en el que se muestra un ensamblado que tiene su propio instalador.The following example, plus the examples in the InstallException constructors, together make up an example showing an assembly having its own installer. El instalador se denomina MyInstaller, que tiene un atributo RunInstallerAttribute, que indica que Installutil. exe invocará este instalador (herramienta de instalación).The installer is named MyInstaller, which has an attribute RunInstallerAttribute, indicating that this installer will be invoked by Installutil.exe (Installer Tool). Installutil. exe (herramienta de instalación) llama a los Commitmétodos Rollback, Install y Uninstall.Installutil.exe (Installer Tool) calls the methods Commit, Rollback, Install and Uninstall. El código de Commit supone que un archivo denominado FileDoesNotExist.txt existe antes de que se pueda confirmar la instalación del ensamblado.The code in Commit presumes that a file named FileDoesNotExist.txt exists before the installation of the assembly can be committed. Si el archivo FileDoesNotExist.txt no existe, Commit genera una InstallException.If the file FileDoesNotExist.txt does not exist, Commit raises an InstallException. Lo mismo sucede con Uninstall en el que una desinstalación solo se producirá si un archivo denominado FileDoesNotExist.txt existe.The same is the case with Uninstall in which an uninstallation will only happen if a file named FileDoesNotExist.txt exists. En caso contrario, InstallExceptiongenera un.Otherwise it raises an InstallException. En Rollback, se ejecuta un fragmento de código, lo que podría producir una excepción.In Rollback, a code fragment is executed, which might raise an exception. Si se produce la excepción, se detecta y se genera InstallException una con esa excepción que se le pasa.If the exception is raised, it is caught and an InstallException is raised with that exception being passed to it.

Nota

Ejecute este ejemplo con la ayuda de Installutil. exe.Run this example with the help of Installutil.exe. Escriba esto en el símbolo del sistema:Type this in the command prompt:

Installutil InstallException.exe

O bien-or-

Installutil /u InstallException.exe

#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)]
ref class MyInstaller: public Installer
{
public:
   virtual void Install( IDictionary^ savedState ) override
   {
      Installer::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();
   }


   virtual void Commit( IDictionary^ savedState ) override
   {
      Installer::Commit( savedState );
      Console::WriteLine( "Commit ..." );
      
      // Throw an error if a particular file doesn't exist.
      if (  !File::Exists( "FileDoesNotExist.txt" ) )
            throw gcnew InstallException;

      
      // Perform the final installation if the file exists.
   }


   virtual void Rollback( IDictionary^ savedState ) override
   {
      Installer::Rollback( savedState );
      Console::WriteLine( "RollBack ..." );
      try
      {
         
         // Performing some activity during rollback that raises an 'IOException*'.
         throw gcnew IOException;
      }
      catch ( Exception^ e ) 
      {
         throw gcnew InstallException( "IOException* raised",e );
      }

      
      // Perform the remaining rollback activites if no exception raised.
   }


   virtual void Uninstall( IDictionary^ savedState ) override
   {
      Installer::Uninstall( savedState );
      Console::WriteLine( "UnInstall ..." );
      
      // Throw an error if a particular file doesn't exist.
      if (  !File::Exists( "FileDoesNotExist.txt" ) )
            throw gcnew InstallException( "The file 'FileDoesNotExist'  does not exist" );

      
      // Perform the uninstall activites if the file exists.
   }

};

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

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

Constructores

InstallException()

Inicializa una nueva instancia de la clase InstallException.Initializes a new instance of the InstallException class.

InstallException(SerializationInfo, StreamingContext)

Inicializa una nueva instancia de la clase InstallException con datos serializados.Initializes a new instance of the InstallException class with serialized data.

InstallException(String)

Inicializa una nueva instancia de la clase InstallException y especifica el mensaje que se va a mostrar al usuario.Initializes a new instance of the InstallException class, and specifies the message to display to the user.

InstallException(String, Exception)

Inicializa una nueva instancia de la clase InstallException y especifica el mensaje que se va a mostrar al usuario y una referencia a la excepción interna que ha provocado esta excepción.Initializes a new instance of the InstallException class, and specifies the message to display to the user, and a reference to the inner exception that is the cause of this exception.

Propiedades

Data

Obtiene una colección de pares clave-valor que proporcionan más información definida por el usuario sobre la excepción.Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Heredado de Exception)
HelpLink

Obtiene o establece un vínculo al archivo de ayuda asociado a esta excepción.Gets or sets a link to the help file associated with this exception.

(Heredado de Exception)
HResult

Obtiene o establece HRESULT, un valor numérico codificado que se asigna a una excepción específica.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Heredado de Exception)
InnerException

Obtiene la instancia Exception que produjo la excepción actual.Gets the Exception instance that caused the current exception.

(Heredado de Exception)
Message

Obtiene un mensaje que describe la excepción actual.Gets a message that describes the current exception.

(Heredado de Exception)
Source

Devuelve o establece el nombre de la aplicación o del objeto que generó el error.Gets or sets the name of the application or the object that causes the error.

(Heredado de Exception)
StackTrace

Obtiene una representación de cadena de los marcos inmediatos en la pila de llamadas.Gets a string representation of the immediate frames on the call stack.

(Heredado de Exception)
TargetSite

Obtiene el método que produjo la excepción actual.Gets the method that throws the current exception.

(Heredado de Exception)

Métodos

Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Heredado de Object)
GetBaseException()

Cuando se reemplaza en una clase derivada, devuelve la clase Exception que representa la causa principal de una o más excepciones posteriores.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Heredado de Exception)
GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Heredado de Object)
GetObjectData(SerializationInfo, StreamingContext)

Cuando se reemplaza en una clase derivada, establece SerializationInfo con información sobre la excepción.When overridden in a derived class, sets the SerializationInfo with information about the exception.

(Heredado de Exception)
GetType()

Obtiene el tipo de tiempo de ejecución de la instancia actual.Gets the runtime type of the current instance.

(Heredado de Exception)
MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Heredado de Object)
ToString()

Crea y devuelve una representación de cadena de la excepción actual.Creates and returns a string representation of the current exception.

(Heredado de Exception)

Eventos

SerializeObjectState

Ocurre cuando una excepción se serializa para crear un objeto de estado de excepción que contenga datos serializados sobre la excepción.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Heredado de Exception)

Se aplica a

Consulte también: