1

In Visual Studio 2022, I've written the following C# (.NET 6) code (in case it matters, it's in a non-generic class derived from a generic base class):

private async Task<bool> MyMethod()
{
    var method = MethodBase.GetCurrentMethod()!;
    string methodName = method.Name;
    Logger.LogInformation("Entering method {method}", methodName);
    // ... etc. ...

After I ran the application, I inspected the log and found that, instead of "MyMethod", it had written "MoveNext" as the method name.

To troubleshoot this, I--well, first I broke what had been one line into the first three lines of the method body shown above--and then I put a breakpoint on the Logger.LogInformation line, ran the application in Debug mode, and checked the Locals window at the breakpoint. The value it shows for method is "{Void MoveNext()}"!

Why isn't it picking up the actual method it's in? Where is it getting MoveNext from?

Green Grasso Holm
  • 468
  • 1
  • 4
  • 18

0 Answers0