InstallException Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Eccezione generata quando si verifica un errore durante la fase di commit, rollback o disinstallazione di un'installazione.
public ref class InstallException : SystemException
[System.Serializable]
public class InstallException : SystemException
[<System.Serializable>]
type InstallException = class
inherit SystemException
Public Class InstallException
Inherits SystemException
- Ereditarietà
- Attributi
Esempio
L'esempio seguente, più gli esempi nei InstallException costruttori, costituiscono un esempio che mostra un assembly con un proprio programma di installazione. Il programma di installazione è denominato MyInstaller, che ha un attributo RunInstallerAttribute, che indica che il programma di installazione verrà richiamato da Installutil.exe (Strumento di installazione).
Installutil.exe (strumento di installazione) chiama i metodi Commit, RollbackInstall e Uninstall. Il codice in Commit presuppone che esista un file denominato FileDoesNotExist.txt prima di poter eseguire il commit dell'installazione dell'assembly. Se il file FileDoesNotExist.txt non esiste, Commit genera un oggetto InstallException. Lo stesso vale per il caso in Uninstall cui si verifica una disinstallazione solo se esiste un file denominato FileDoesNotExist.txt . In caso contrario, genera un oggetto InstallException. In Rollbackviene eseguito un frammento di codice che potrebbe generare un'eccezione. Se viene generata l'eccezione, viene intercettata e viene generata un'eccezione InstallException con tale eccezione passata.
Note
Eseguire questo esempio con l'aiuto di Installutil.exe. Digitare questo nel prompt dei comandi:
Installutil InstallException.exe
oppure
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
Costruttori
| Nome | Descrizione |
|---|---|
| InstallException() |
Inizializza una nuova istanza della classe InstallException. |
| InstallException(SerializationInfo, StreamingContext) |
Inizializza una nuova istanza della classe InstallException con dati serializzati. |
| InstallException(String, Exception) |
Inizializza una nuova istanza della InstallException classe e specifica il messaggio da visualizzare all'utente e un riferimento all'eccezione interna che è la causa di questa eccezione. |
| InstallException(String) |
Inizializza una nuova istanza della InstallException classe e specifica il messaggio da visualizzare all'utente. |
Proprietà
| Nome | Descrizione |
|---|---|
| Data |
Ottiene una raccolta di coppie chiave/valore che forniscono informazioni aggiuntive definite dall'utente sull'eccezione. (Ereditato da Exception) |
| HelpLink |
Ottiene o imposta un collegamento al file della Guida associato a questa eccezione. (Ereditato da Exception) |
| HResult |
Ottiene o imposta HRESULT, valore numerico codificato assegnato a un'eccezione specifica. (Ereditato da Exception) |
| InnerException |
Ottiene l'istanza Exception che ha causato l'eccezione corrente. (Ereditato da Exception) |
| Message |
Ottiene un messaggio che descrive l'eccezione corrente. (Ereditato da Exception) |
| Source |
Ottiene o imposta il nome dell'applicazione o dell'oggetto che causa l'errore. (Ereditato da Exception) |
| StackTrace |
Ottiene una rappresentazione di stringa dei fotogrammi immediati nello stack di chiamate. (Ereditato da Exception) |
| TargetSite |
Ottiene il metodo che genera l'eccezione corrente. (Ereditato da Exception) |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetBaseException() |
Quando sottoposto a override in una classe derivata, restituisce l'oggetto Exception che rappresenta la causa radice di una o più eccezioni successive. (Ereditato da Exception) |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
In caso di override in una classe derivata, imposta con le SerializationInfo informazioni sull'eccezione. (Ereditato da Exception) |
| GetType() |
Ottiene il tipo di runtime dell'istanza corrente. (Ereditato da Exception) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Crea e restituisce una rappresentazione di stringa dell'eccezione corrente. (Ereditato da Exception) |
Eventi
| Nome | Descrizione |
|---|---|
| SerializeObjectState |
Si verifica quando viene serializzata un'eccezione per creare un oggetto stato dell'eccezione contenente dati serializzati sull'eccezione. (Ereditato da Exception) |