我在.NET 2.0 SP2在我的ClickOnce部署的应用程序的依赖
(在 ApplicationDeployment.CurrentDeployment.CheckForDetailedUpdate(假)
方法是SP2只)。
I have a dependency on .NET 2.0 SP2 in my ClickOnce deployed application
(the ApplicationDeployment.CurrentDeployment.CheckForDetailedUpdate(false)
method is SP2 only).
我想检查SP2是否是在应用程序启动时present。我曾尝试通过调用SP2的唯一方法后赶上的MissingMethodException检测到这一点。
I would like to check whether SP2 is present during app startup. I have tried to detect this by catching MissingMethodException after calling a SP2-only method.
/// <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();
}
}
在code在追赶从未执行时,这个运行在.NET 2.0没有SP2。唯一的例外是只抓到了 AppDomain.CurrentDomain.UnhandledException
事件处理程序。
这怎么可能是的MissingMethodException不抓?我可以想像,这是一个特例 - 在CLR打一个不存在的方法,并不知它是不可能把它传递给catch块。我想了解这背后的原理。
How is it possible that the MissingMethodException is not caught? I can imagine that this is a special case - the CLR hits a method that does not exist and somehow it is not possible to pass this to the catch block. I would like to understand the principle behind this.
任何人有任何关于此问题的资源?是否有不能被捕获在catch块中的任何其他异常?
Anyone has any resources on this issue? Are there any other exceptions that cannot be caught in a catch block?
我怀疑这是发生在JIT时,该方法是正确的,甚至进入前 - 即在你的catch块击中。它的可能的,如果你赶上的MissingMethodException
在呼叫的方法,将梳理出来......特别是如果你装饰 CheckDotNet2SP
与 MethodImpl [MethodImplOptions.NoInlining]
。它仍然听起来就像将pretty的冒险,但。
I suspect it's happening at JIT time, before the method is even properly entered - i.e. before your catch block is hit. It's possible that if you catch MissingMethodException
in the calling method, that will sort it out... particularly if you decorate CheckDotNet2SP
with MethodImpl[MethodImplOptions.NoInlining]
. It still sounds like it would be pretty dicey though.
您可以随时检查的方法与反思的presence而不是试图尽管调用它。
You could always check for the presence of the method with reflection rather than by trying to call it though.