I have a .net 4.0 class lib project and when I compile it in release I noticed the binary (.dll) is not smaller in size than the debug. Why is this? Shouldn't it be smaller? It should also execute a bit faster no? Also, how can I tell if a .dll has been built as debug or release?
-
This depends on the size of the build. If you have a large build, requiring many symbols to be saved for debugging, the release might be significantly smaller. – bash.d Mar 19 '13 at 21:12
-
@bash.d: debug is 98K and release is 97K. – genxgeek Mar 20 '13 at 04:11
2 Answers
Debug and Release executables (dll's, exe, whatever) are identical unless you use #if DEBUG compiler directives in your code. Difference is that a debug compile generates .pdb files containing debugging info.
This tool can help you to find out if the dll is debug or release: http://assemblyinformation.codeplex.com

- 109
- 10
There is very little difference in the IL that the C# compiler generates when you build the Release version of your assembly. The only notable thing it does is omit the NOP instructions that help you set a breakpoint on a curly brace. Just a few tidbits beyond that like not emitting an empty class constructor. All small stuff, only related to making it easier to debug code. Given the default /filealign
option, odds are good that the resulting assembly is not smaller. Or is just a few kilobytes less.
The C# compiler doesn't have a built-in optimizer, that's not its job. The optimizer is built into the jitter. Controlled by an attribute that the compiler emits, DebuggableAttribute.IsJITOptimizerEnabled property. Which is true for the Debug build and false for the Release build. You can see its value with ildasm.exe
You'll find the kind of optimizations performed by the jitter described in this answer.

- 1
- 1

- 922,412
- 146
- 1,693
- 2,536