堆栈深度因路径而异
本文关键字:路径 深度 堆栈 | 更新日期: 2023-09-27 18:16:26
我在.dll的发布版本上运行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");
}
}
}
我不知道为什么这个错误只发生在发布版本中
虽然可能与OP的问题没有直接关系,但我刚刚也遇到了这个错误。我正在生成用于反序列化HashSet<T>
的IL代码-问题是评估堆栈不平衡,因为HashSet<T>
中的Add
方法返回bool,而不是void。调用它会推入一个我不关心的布尔值。在Add调用之后调用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();