似乎 StackFrame.ILOffset 为 Microsoft 中的动态方法返回 -1。在 Linux 下与 Mono 一起工作正常。
public static string PrintExceptionStack (Exception ex)
{
StackTrace st = new StackTrace (ex, true);
foreach (StackFrame sf in st.GetFrames ()) {
MethodBase meth = sf.GetMethod ();
int iloffset = sf.GetILOffset ();
// prints -1 for dynamic methods in Microsoft (VS 2017)
// prints correct value with Mono in Linux
Console.WriteLine (meth.Name + " " + iloffset);
// this works in Microsoft (as well as Linux Mono)
int natoffs = sf.GetNativeOffset ();
Console.WriteLine (meth.Name + " " + natoffs);
}
}
我在https://blogs.msdn.microsoft.com/jmstall/2005/02/03/debugging-dynamically-generated-code-reflection-emit上尝试了可调试属性的东西,但它没有任何区别。
DebuggableAttribute.IsJITTrackingEnabled 的 MS 文档还指出,运行时始终为 v2 及更高版本生成 native-to-iloffset,因此在任何情况下似乎都没有必要。 https://msdn.microsoft.com/en-us/library/system.diagnostics.debuggableattribute.isjittrackingenabled%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
我错过了什么还是坏了?谢谢