debugging - Different C# Output Between Release and Debug -


i've little c# program here produces different output between debug , release versions. empty output release version is, think, consistent c# language specification. program should not produce output, yet debug version does.

i've run both release , debug versions command line (outside vs environment) , same inconsistent output. i've decompiled debug version (using ildasm) , re-compiled ilasm. when this, newly compiled program behaves release version. can imagine when de-compile , re-compile being left out i've not been able determine what's different.

regarding exe file size: both release , debug versions produced vs have same file size: 5,120 bytes. when de-compile , re-compile, both versions again have same, smaller file size: 3,072.

the program quite small , i've looked @ il in reflector , can't see cause difference in output.

does have (hopefully detailed) explanation of why there difference?

please note i'm not trying make debug , release versions consistent, necessarily, want understand why not.

recall said above -- both debug , release versions produce different output even when run command line. if tell me runtime doing kind of optimization release version not debug version there must embedded in debug/release version assemblies tell runtime turn on/off optimizations. embedded "something" , why not carry on when using ildasm/ilasm?

here's code:

using system;  class test {     static int value = 0;     static int = initialize("assigning a");     static int b = initialize("assigning b");     static string name = "fred";     static int c = initialize("assigning c");      static int initialize(string mssg) {         ++value;         console.writeline("in initialize() :: {0}, name={1}, returning {2}", mssg, name, value);         return value;     } // initialize()      static void main() {     } // main() } // class test 

and here output visual studio generated debug version:

in initialize() :: assigning a, name=, returning 1 in initialize() :: assigning b, name=, returning 2 in initialize() :: assigning c, name=fred, returning 3 

running release version generates no output.

the static class initializer not called until needed. debug , release versions decided differently when needed. in particular guess release build optimized main out entirely , never loaded class. seems have decided since main nothing can optimize out - in case seems bad decision


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -