J'ai une dépendance sur .NET 2.0 SP2 dans mon application déployée ClickOnce (la méthode ApplicationDeployment.CurrentDeployment.CheckForDetailedUpdate(false)
est SP2 uniquement).Pourquoi est-il impossible d'attraper MissingMethodException?
Je voudrais vérifier si SP2 est présent lors du démarrage de l'application. J'ai essayé de détecter ceci en attrapant MissingMethodException après avoir appelé une méthode SP2-only.
/// <summary>
/// The SP2 bootstrapper does not allow HomeSite installation
/// http://msdn.microsoft.com/en-us/vstudio/bb898654.aspx
/// So we only advice the user to download .NET 2.0 SP2 manually.
/// </summary>
private void CheckDotNet2SP()
{
WaitHandle wh = new AutoResetEvent(true);
try
{
wh.WaitOne(1); //this method is .NET 2.0 SP2 only
}
//NOTE: this catch does not catch the MissingMethodException
catch (Exception) //change to catch(MissingMethodException) does not help
{
//report that .NET 2.0 SP2 is missing
}
finally
{
wh.Close();
}
}
Le code dans catch ne s'exécute jamais lorsque cela s'exécute sur .NET 2.0 sans SP2. L'exception est interceptée uniquement par le gestionnaire d'événements AppDomain.CurrentDomain.UnhandledException
.
Comment est-il possible que MissingMethodException ne soit pas interceptée? Je peux imaginer que c'est un cas particulier - le CLR frappe une méthode qui n'existe pas et d'une manière ou d'une autre il n'est pas possible de passer cela au bloc catch. Je voudrais comprendre le principe derrière cela.
Quelqu'un a des ressources sur ce problème? Existe-t-il d'autres exceptions qui ne peuvent pas être interceptées dans un bloc catch?
pouvez-vous s'il vous plaît énumérer d'autres types d'exception 'irrécupérable'? – Marek
@Marek: fait, j'ai mis à jour la réponse. – Abel
Avez-vous une référence pour ces exceptions "irrécupérables"? Je vois qu'il est référencé dans [Application.DispatcherUnhandledException] (http://msdn.microsoft.com/en-us/library/system.windows.application.dispatcherunhandledexception%28v=vs.85%29.aspx), mais je ne trouve pas d'informations définitives. –