【发布时间】:2013-05-02 10:37:33
【问题描述】:
在后台线程中,我的应用程序会定期检查网络文件夹(UNC 路径)以获取应用程序更新。它读出文件的汇编版本,如下所示:
Try
newVers = System.Reflection.AssemblyName.GetAssemblyName("\\server\app.exe").Version
Catch ex As Exception
' ignore
End Try
这个 sn-p 经常执行,到目前为止,我估计在多个客户站点上总共执行了 100.000 多次,没有问题。
有时,GetAssemblyName 会引发FileNotFoundException,例如在无法访问网络文件夹的情况下(可能会发生并且必须处理)。这个异常被下面的Catch 块捕获,一切正常。
然而,在报告的三个案例中,GetAssemblyName 调用引发了SEHException。奇怪的是,这个异常并没有被下面的Catch 块捕获,而是被我的全局未处理异常处理程序(System.AppDomain.CurrentDomain.UnhandledException)捕获。结果,应用程序崩溃。
这是异常详细信息(不幸的是,我的错误处理例程没有记录异常的 ErrorCode 和 CanResume 字段):
Caught exception: System.Runtime.InteropServices.SEHException
Message: External component has thrown an exception.
Source: mscorlib
TargetSite: System.Reflection.AssemblyName nGetFileInformation(System.String)
StackTrace:
at System.Reflection.AssemblyName.nGetFileInformation(String s)
at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
at SyncThread.Run()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
为什么异常没有被下面的Catch 块捕获?
(也许这是相关的:这只发生在客户站点上,其中 UNC 路径指向的服务器不是本地网络的一部分,而是 VPN 上的远程服务器。)
【问题讨论】:
-
在我们的例子中,我们使用 Telerik RadGridView 并且在添加行时偶尔会获得其中之一。我有同样的问题,为什么它不会被抓住。感谢 Andreas 的提问和@porges 的回答。