在后台线程中,我的应用程序会定期检查网络文件夹(UNC 路径)以获取应用程序更新。它读出文件的汇编版本,如下所示:
Try
newVers = System.Reflection.AssemblyName.GetAssemblyName("\\server\app.exe").Version
Catch ex As Exception
' ignore
End Try
这个片段经常被执行,到目前为止,我猜在多个客户网站上总共执行了超过 100.000 次,没有问题。
有时,GetAssemblyName
会引发 a 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 上的远程服务器。)