I was going over the MbUnit issue list and came across Issue 97. This had a really interesting scenario. Basically, Firefox was the default web browser but didn’t have a profile associated with it (it hadn’t been executed yet) and when you try and launch it via Process.Start it will load firefox correctly however also throw a Win32Exception.
If you did something like this:
Process.Start(http://www.google.co.uk);
The exception would be:
System.ComponentModel.Win32Exception was unhandled
Message=”The system cannot find the file specified”
Source=”System”
ErrorCode=-2147467259
NativeErrorCode=2
StackTrace:
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
at ConsoleApplication1.Program.Main(String[] args) in ……Program.cs:line 13
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Very strange, if anyone knows the extract reason why it decides to thrown an exception please leave a comment. Definitely something to be aware might happen. Wonder how many applications would crash because of this…
When testing your applications, if you want to reproduce this without having to load a clean VM, go into your %AppData% and move the Mozilla directory to another location. Next time you load Firefox, the dialog will be displayed and the exception will be thrown.
Outlook also hates it…
Great work, this error has been causing issues annoyances (is that a word) in some of our environments. It’s great to finally get rid of it!
The only way I have found around this is to use a try block and catch the exception knowing that it is a red herring in this case.