当发布dll不工作但调试dlls [英] When release dlls don't work but debug dlls do

查看:112
本文介绍了当发布dll不工作但调试dlls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将庞大的分布式系统部署到我们的客户之后,我们遇到了一个意想不到的错误。在调查期间,我们更换组件导致错误,我们添加了一些诊断代码。我们使用的dll内置在调试模式。突然间,这一切都起作用!

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!

使用发行版(使用诊断代码)替换debug dll会使其再次崩溃。

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.

(该项目混合了C#和VB.NET,麻烦程序集是VB.NET ..,如果这有任何差异)

(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.

推荐答案

对于原因...好的,一些症状的提示会有所帮助。一种可能性是您有一个方法,如 Debug.WriteLine ,具有副作用(即使其工作)。没有编辑标有 [Conditional(...)] 的方法的调用,除非您有正确的符号定义 - 所以任何标记为 [Conditional( DEBUG)] 将被静默地删除。

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?

作为上述的一个例子:

    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";
    }

以DEBUG模式编译,它打印我正在工作;编译在RELEASE模式下,它打印我坏了。这听起来是否相似?检查你没有直接使用具有副作用的东西调用任何调试方法。在大多数情况下,您可以通过间接方式修复:

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.

这篇关于当发布dll不工作但调试dlls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆