In a background thread, my application regularly examines a network folder (UNC Path) for application updates. It reads out the assembly version of the file, like so:
Try
newVers = System.Reflection.AssemblyName.GetAssemblyName("\\server\app.exe").Version
Catch ex As Exception
' ignore
End Try
This snippet is executed quite often, in total I'd guess way more than 100.000 times on multiple customer sites so far without a problem.
Sometimes, GetAssemblyName
raises a FileNotFoundException
, for instance in case the network folder is not reachable (which can happen and must be dealt with). This exception is caught by the Catch
block just below, and everything works just fine.
In three reported cases, however, the GetAssemblyName
call raised an SEHException
. The strange thing is that this exception was not caught by the Catch
block just below, but by my global unhandled exception handler (System.AppDomain.CurrentDomain.UnhandledException
). As a result, the application crashes.
Here is the exception detail (unfortunately, the ErrorCode
and CanResume
fields of the exception are not logged by my error handling routine):
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()
Why is is that the exception is not caught by the Catch
block just below?
(Maybe this is relevant: this has only happened on customer sites, where the UNC path pointed to a server that was not part of the local network, but a remote server on a VPN.)