I noticed that an application that I am developing (a game written in C# / XNA) occasionally behaves differently depending on whether it is started from within Microsoft Visual Studio (2010) compared to when it is started outside MSVS (e.g. from Windows Explorer). Specifically, sometimes I get errors (exceptions are drawn) that do not occur within MSVS.
What could be the reason for this difference? Ideally there would be a way to make MSVS check the application as strictly as possible such that I can be sure that all bugs really occur (and can be fixed) during development.
The problem happens in both release and debug mode. The game uses a number of external dlls (nuclex lib, sharp dx) but these libs are all used both from within MSVS and outside. The game entirely runs in a single thread.
Please note that the question is not about a specific error that I need to debug, but it is about general differences that (could) arise from the way an application is started.
There are two main things that cause your program to run differently, when run in Visual Studio.
First of all, the Visual Studio hosting process. I think it’s disabled by default. But the toggle for it, if you need it, is in the “Debug” tab of the properties for your application project.
The second, is the fact that the .NET JIT will emit different, more debuggable machine code when a debugger is attached. You can disable this behaviour by unchecking the “Suppress JIT optimization on module load (Managed only)” checkbox in Tools -> Options -> Debugging -> General.
You could try disabling this option and then running your game under the debugger and seeing if the same error occurs. Note, of course, that disabling this will make your program significantly harder to debug – but it does help in a case like this one.
As was mentioned in comments, it is almost unheard of for this kind of problem to be related to the code-generation (although, theoretically, I suppose it’s possible). Latent threading bugs caused by changes in performance are far more likely. It could also be a badly behaved native library – although this is also unusual.