InstallException InstallException InstallException InstallException Class

Definizione

Eccezione generata quando si verifica un errore durante la fase di commit, rollback o disinstallazione di un'installazione.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
Ereditarietà
Attributi

Esempi

Nell'esempio seguente, oltre a esempi nel InstallException costruttori, costituiscono un esempio che illustra un assembly che ha un proprio programma di installazione.The following example, plus the examples in the InstallException constructors, together make up an example showing an assembly having its own installer. Il programma di installazione è denominato MyInstaller, che ha un attributo RunInstallerAttribute, che indica che il programma di installazione verrà richiamato dal Installutil.exe (strumento Installer).The installer is named MyInstaller, which has an attribute RunInstallerAttribute, indicating that this installer will be invoked by Installutil.exe (Installer Tool). Installutil.exe (strumento Installer) chiama i metodi Commit, Rollback, Install e Uninstall.Installutil.exe (Installer Tool) calls the methods Commit, Rollback, Install and Uninstall. Il codice nel Commit presuppone che un file denominato FileDoesNotExist.txt esiste prima che l'installazione dell'assembly può essere eseguito il commit.The code in Commit presumes that a file named FileDoesNotExist.txt exists before the installation of the assembly can be committed. Se il file FileDoesNotExist.txt non esiste, Commit genera un InstallException.If the file FileDoesNotExist.txt does not exist, Commit raises an InstallException. Lo stesso avviene con Uninstall in una disinstallazione verrà eseguito solo se un file denominato FileDoesNotExist.txt esiste.The same is the case with Uninstall in which an uninstallation will only happen if a file named FileDoesNotExist.txt exists. In caso contrario, genera un InstallException.Otherwise it raises an InstallException. In Rollback, viene eseguito un frammento di codice, che potrebbe generare un'eccezione.In Rollback, a code fragment is executed, which might raise an exception. Se viene generato l'eccezione, vengono rilevate e un InstallException generato con tale eccezione viene passata a esso.If the exception is raised, it is caught and an InstallException is raised with that exception being passed to it.

Nota

Eseguire questo esempio con l'aiuto di Installutil.exe.Run this example with the help of Installutil.exe. Digitare quanto segue al prompt dei comandi:Type this in the command prompt:

Installutil InstallException.exe

In alternativa-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
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

Costruttori

InstallException() InstallException() InstallException() InstallException()

Inizializza una nuova istanza della classe InstallException.Initializes a new instance of the InstallException class.

InstallException(SerializationInfo, StreamingContext) InstallException(SerializationInfo, StreamingContext) InstallException(SerializationInfo, StreamingContext) InstallException(SerializationInfo, StreamingContext)

Inizializza una nuova istanza della classe InstallException con dati serializzati.Initializes a new instance of the InstallException class with serialized data.

InstallException(String) InstallException(String) InstallException(String) InstallException(String)

Inizializza una nuova istanza della classe InstallException e specifica il messaggio che verrà visualizzato all'utente.Initializes a new instance of the InstallException class, and specifies the message to display to the user.

InstallException(String, Exception) InstallException(String, Exception) InstallException(String, Exception) InstallException(String, Exception)

Inizializza una nuova istanza della classe InstallException e specifica il messaggio da visualizzare e un riferimento all'eccezione interna che è la causa dell'eccezione corrente.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.

Proprietà

Data Data Data Data

Ottiene una raccolta di coppie chiave-valore che fornisce informazioni aggiuntive definite dall'utente relative all'eccezione.Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Inherited from Exception)
HelpLink HelpLink HelpLink HelpLink

Ottiene o imposta un collegamento al file della Guida associato all'eccezione.Gets or sets a link to the help file associated with this exception.

(Inherited from Exception)
HResult HResult HResult HResult

Ottiene o imposta HRESULT, un valore numerico codificato che viene assegnato a un'eccezione specifica.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Inherited from Exception)
InnerException InnerException InnerException InnerException

Ottiene l'istanza di Exception che ha causato l'eccezione corrente.Gets the Exception instance that caused the current exception.

(Inherited from Exception)
Message Message Message Message

Ottiene un messaggio che descrive l'eccezione corrente.Gets a message that describes the current exception.

(Inherited from Exception)
Source Source Source Source

Ottiene o imposta il nome dell'oggetto o dell'applicazione che ha generato l'errore.Gets or sets the name of the application or the object that causes the error.

(Inherited from Exception)
StackTrace StackTrace StackTrace StackTrace

Ottiene una rappresentazione di stringa dei frame immediati nello stack di chiamate.Gets a string representation of the immediate frames on the call stack.

(Inherited from Exception)
TargetSite TargetSite TargetSite TargetSite

Ottiene il metodo che genera l'eccezione corrente.Gets the method that throws the current exception.

(Inherited from Exception)

Metodi

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetBaseException() GetBaseException() GetBaseException() GetBaseException()

Se utilizzato come metodo di override in una classe derivata, restituisce l'Exception che è la causa radice di una o più eccezioni successive.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Inherited from Exception)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

Quando l'override viene eseguito in una classe derivata, imposta il controllo SerializationInfo per la colonna.When overridden in a derived class, sets the SerializationInfo with information about the exception.

(Inherited from Exception)
GetType() GetType() GetType() GetType()

Ottiene il tipo di runtime dell'istanza corrente.Gets the runtime type of the current instance.

(Inherited from Exception)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Crea e restituisce una rappresentazione di stringa dell'eccezione corrente.Creates and returns a string representation of the current exception.

(Inherited from Exception)

Eventi

SerializeObjectState SerializeObjectState SerializeObjectState SerializeObjectState

Si verifica quando un'eccezione viene serializzata per creare un oggetto di stato eccezione contenente i dati serializzati relativi all'eccezione.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Inherited from Exception)

Si applica a

Vedi anche