简体   繁体   中英

System.Diagnostics.StackFrame.GetFrame(index) not found in mscorlib

I created two console applications, both targeting v4.5.2 of the .NET framework.

class MyDisposable : IDisposable
{
    public void Dispose()
    {
        var callerName = new StackTrace().GetFrame(1)?.GetMethod()?.Name;

        Console.WriteLine($"Dispose called by {callerName}.");
    }
}

which run perfectly well.

In the other, I have the following, which are in effect the same.

return Disposable.Create(() =>
{
    var stackFrame = new StackFrame();
    var callingMethodBase = stackFrame.GetFrame(1)?.GetMethod();

    ...
});

But Visual Studio intellisense reports:

'StackFrame' does not contain a definition for 'GetFrame' and no extension method 'GetFrame' accepting a first argument of type 'StackFrame' could be found (are you missing a using directive or an assembly reference?)

When I Go to Definition on the StackFrames class, I see the method GetFrames is absent from the class declaration of the StackFrame class. Both the assembly versions for mscorlib are the same, ie v4.0.0.0.

Why is that?

In the first example you are using StackTrace , but in the second you are using StackFrame .

Stack Trace has the method GetFrame(), but Stack Frame doesn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM