After deploying our huge distributed system to one of our clients we experience an unexpected error. During the investigation we replace the assembly causing the error with one where we have added some diagnostic code. The dll we use is built in debug mode. And suddenly it all works!
Replacing the debug dll with the release version (with the diagnostic code) makes it crash again.
There are no precompiler directives, conditional debug attributes etc. in our code. The problem has been found in two different installation sites, while it works fine in several more.
(The project has a mix of C# and VB.NET, the troublesom assembly is VB.NET.., if that makes any difference)
So the question is: What do you do in situations like this? And what can be the cause - in general? Any advice on debugging this issue is welcome.
Lots of your code could be completely removed or rewritten in Release mode. The resulting executable will most likely not match up with your written code. Because of this release mode will run faster than debug mode due to the optimizations.
In Debug mode, there are no optimizations, which means debug builds can run slower than Release build.
Release CRT makes the code faster in 2x times, given that inlining is disabled. Release CRT and inlining have major synergy, providing impressive x14 boost together when Runtime Checks are disabled. Default Debug build is x240 times slower than default Release build.
For causes... well, some hint of the symptom would help. One possibility is that you have code to a method like Debug.WriteLine
that has side effects (i.e. makes it work). Calls to methods marked with [Conditional(...)]
are not compiled unless you have the right symbols defined - so anything marked [Conditional("DEBUG")]
will be silently dropped.
It could also be a compiler bug, but that is a bit unlikely (but not impossible).
What is the symptom? How does it break?
As an example of the above:
static string Bar { get; set; }
static void Main()
{
Bar = "I'm broken";
Debug.WriteLine(Foo());
Console.WriteLine(Bar);
}
// note Foo only called in DEBUG builds
static string Foo()
{
Bar = "I'm working";
return "mwahahah";
}
Compiled in DEBUG mode it prints "I'm working"; compiled in RELEASE mode it prints "I'm broken". Does this sound similar? Check you aren't calling any debug methods directly with things that have side-effects. In most cases, you can fix by indirection:
string foo = Foo();
Debug.WriteLine(foo);
Now it gets called in either mode.
You can try and turn off Optimize Code in the Build Settings. What is the actual error you are getting.
Another thing you can do is compile in release mode but enable the #Debug conditional. This will handle the case if your using Diagnostics.Debug and the code in there effects your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With