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