Thanks for all your responses.
We did some testing, and I finally managed to make my developer machine throw some NullReferenceException exceptions. It still throws a lot more frequently on my boss's machine, though.
The most common place for the exception to be thrown is when I call System.Diagnostics.Process.Start( fileNameString ) to open MS Excel.
It appears to happen completely at random, but when it does happen, the top of the stack trace is:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Win32.NativeMethods.ShellExecuteEx(ShellExecuteInfo info)
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)
I created a test program to try to reproduce this problem with certain test cases:
- create a file with an invalid extension,
- create a .xls file that Excel can't read
- make the filename a null string
- edit important values in the .xls file with a hex editor
But all errors thrown resulted in a different sort of exception which was always thrown before Microsoft.Win32.NativeMethods.ShellExecuteEx(ShellExecuteInfo info).
Furthermore, putting a break point before the function revealed that the filename was always valid.
Well, anyway, thanks for all your responses, and I don't expect anyone to try to debug my code for me, but I'm really curious as to why it fails on a function (System.Diagnostics.Process.Start) that I use all the time and has never given me this kind of trouble before.