我有一个像这样的方法调用序列:
//This is the Load method
BusinessLogic.Models.ProjectEngineer p = new BusinessLogic.Models.ProjectEngineer(project);
p.IsQualifiedFor(enType, educationEnum);
.
.
.
[UsesRule]
public static void IsQualifiedFor(this Models.ProjectEngineer p, EngineerTypeEnum enType, FieldEducationEnum fieldEducation)
{
RuleCache.EvaluateRule(p, enType, fieldEducation);
}
.
.
.
public static bool EvaluateRule<TClass>(TClass sourceObj, params object[] parameters)
{
var frame = new StackTrace().GetFrame(1);
var methodInfo = frame.GetMethod();
var atr = methodInfo.GetCustomAttribute<UsesRuleAttribute>();
if (atr == null)
throw new EISException("You can't call 'EvaluateRule' method in a method that does not have 'UsesRuleAttribute'.");
...
}
它在生产服务器上工作正常,直到今天我改变了一些无关紧要的东西。现在EvaluateRule
方法抛出异常,因为它在调用者中找不到UsesRuleAttribute
。这是异常的堆栈跟踪:
BusinessLogic.EISException: You can't call 'EvaluateRule' method in a method that does not have 'UsesRuleAttribute'.
at BusinessLogic.Rule.RuleCache.EvaluateRule[TClass](TClass sourceObj, Object[] parameters) in e:\EIS\EISMvc\BusinessLogic\Rule\RuleCache.cs:line 146
at EIS.Quota.Owner.EngineerList.Load() in e:\EIS\EISMvc\EIS\Quota\Owner\EngineerList.aspx.cs:line 66
正如您所见,此处缺少IsQualifiedFor
方法调用(这是一种扩展方法)。我在我的机器上调试项目时工作正常。这是某种优化还是什么?
答案 0 :(得分:3)
JIT(即时编译器)很可能是inlined,即在生成的本机代码中被其主体替换,因此它不会出现在堆栈中。
您可以使用MethodImpl
属性阻止内联:
[UsesRule]
[MethodImpl(MethodImplOptions.NoInlining)]
public static void IsQualifiedFor(this Models.ProjectEngineer p, EngineerTypeEnum enType, FieldEducationEnum fieldEducation)