Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When release dlls don't work but debug dlls do

Tags:

.net

debugging

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.

like image 455
Torbjørn Avatar asked Dec 15 '08 13:12

Torbjørn


People also ask

Is release mode faster than debug?

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.

Is debug slower than release?

In Debug mode, there are no optimizations, which means debug builds can run slower than Release build.

How much faster is release than debug?

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.


2 Answers

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.

like image 90
Marc Gravell Avatar answered Sep 22 '22 14:09

Marc Gravell


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.

like image 27
JoshBerke Avatar answered Sep 24 '22 14:09

JoshBerke