C# XNA Visual Studio: Difference between "release" and "debug" modes?

My psychic powers are not great, and it is hard to tell what is going on without actually debugging it. But here's a guess. The issue I discuss here:

Why does this floating-point calculation give different results on different machines?

applies not just to "cross machine" but also to "debug vs release". It is not only possible but likely that the release version of your program is using higher precision math than your debug version. If you have floating point bugs in there then it is entirely possible that just by sheer bad luck you are hitting the bugs only in the higher-precision release version and not in the lower-precision debug version.

Why the difference? Because in the unoptimized version the C# compiler frequently generates code for temporary values as though they were local variables; the jitter then actually allocates temporary locals on the stack, and writes the temporary values from the registers to the locals. Then when it needs them, it reads them back into registers from the temporaries. That journey can cause the value that was in the high-precision register to be truncated to mere 64 bit precision, losing bits of precision.

In the optimized version the C# compiler and the jitter work harder to keep everything in registers all the time, because obviously that is faster and higher precision, though harder to debug.

Good luck. Bugs that only repro in release mode are a total pain.


First, any #if(DEBUG) or #if(RELEASE) pragmas are entered. You may have code in one or the other that should or shouldn't be called, so search for those.

Beyond that, by default Release builds are set to "optimize code", while Debug isn't. Try changing that setting in your release configuration (Project > Properties > Build > "Optimize code") and seeing if that solves the problem.


With debug mode, there is a define in place, (you can confirm this by checking the 'Build Options' when you right click on the solution and select 'Properties' which if used, you can issue the trace calls. In release mode, the define is removed and hence no debugging information is used. If you were to debug that release code, the debugger will not be able to tell what line (original code) it was on even if you specified the location of the source as the code is optimized.

As for your situation, maybe by clearing out the intermediate build files in the release directory or remove the .suo file found in the solution directory might help.

Hope this helps, Best regards, Tom.