peverify错误“堆栈深度因路径而异”

时间:2014-08-04 21:08:36

标签: c# jit peverify

我在.dll的Release版本上运行了peverify并且它给了我错误"堆栈深度因路径而异[":

[IL]: Error: [C:\tfs\EcoSys\SCM\NextGenInstaller\Cmc.Installer\Cmc.Installer.Desktop\bin\Release\Cmc.Installer.Modules.Crm.dll : Cmc.Installer.Modules.Crm.Models.DatabaseInfo::set_Action][offset 0x0000007F] Stack depth differs depending on path.
1 Error(s) Verifying C:\tfs\EcoSys\SCM\NextGenInstaller\Cmc.Installer\Cmc.Installer.Desktop\bin\Release\Cmc.Installer.Modules.Crm.dll

set_Action的代码如下:

public InstallerAction Action
{
    get { return _action; }
    set
    {
        _action = value;

        InstallMainServer = false;
        InstallDistributorServer = false;
        InstallAnalyticsServer = false;
        InstallMediaServer = false;
        InstallWebTrakServer = false;

        switch (DatabaseType)
        {
            case DatabaseType.Main:
                InstallMainServer = (Action == InstallerAction.Install);
                break;
            case DatabaseType.Distributor:
                InstallDistributorServer = (Action == InstallerAction.Install);
                break;
            case DatabaseType.Analytics:
                InstallAnalyticsServer = (Action == InstallerAction.Install);
                break;
            case DatabaseType.Media:
                InstallMediaServer = (Action == InstallerAction.Install);
                break;
            case DatabaseType.WebTrak:
                InstallWebTrakServer = (Action == InstallerAction.Install);
                break;
            default:
                throw new ArgumentOutOfRangeException("DatabaseType");
        }
    }
}

我不知道为什么这个错误只发生在发布版本中。

1 个答案:

答案 0 :(得分:1)

虽然可能与OP的问题没有直接关系,但我也遇到了这个错误。我正在生成用于反序列化HashSet<T>的IL代码 - 问题是评估堆栈没有平衡,因为Add中的HashSet<T>方法返回bool,而不是void。所以调用它会推出一个我不关心的布尔值。在Add call之后立即调用Pop解决了问题。

            //T x; Deserialize(stream, out x, ctx);
            var x = emit.declocal(elementType);
            emit.ldarg_0()
                .ldloca_s(x)
                .ldarg_2()
                .call(deserialize);

            //value.Add(x);
            emit.ldarg_1()
                .ldind_ref()
                .ldloc_s(x)
                .call(add) // returns bool, since we're not using the value we need to pop the stack to keep the balance
                .pop();