ClickOnceをデプロイしたアプリケーションで.NET2.0SP2に依存しています(ApplicationDeployment.CurrentDeployment.CheckForDetailedUpdate(false)
メソッドはSP2のみです)。
アプリの起動時にSP2が存在するかどうかを確認したいと思います。SP2のみのメソッドを呼び出した後、MissingMethodExceptionをキャッチして、これを検出しようとしました。
/// <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();
}
}
これがSP2なしの.NET2.0で実行される場合、catchのコードは実行されません。AppDomain.CurrentDomain.UnhandledException
例外は、イベントハンドラによってのみキャッチされます。
MissingMethodExceptionがキャッチされない可能性はどのようにありますか?これは特殊なケースであると想像できます。CLRは存在しないメソッドにヒットし、どういうわけかこれをcatchブロックに渡すことができません。その背後にある原理を理解したいと思います。
誰かがこの問題に関するリソースを持っていますか?キャッチブロックでキャッチできない他の例外はありますか?