When release dlls don't work but debug dlls do

前端 未结 15 1406
我寻月下人不归
我寻月下人不归 2020-12-30 03:14

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

15条回答
  •  清酒与你
    2020-12-30 04:18

    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.

提交回复
热议问题