cake: NullReferenceException in closure

What You Are Seeing?

A NullReferenceException.

What is Expected?

this != null

What version of Cake are you using?

0.17.0

Are you running on a 32 or 64 bit system?

64 bit

What environment are you running on? Windows? Linux? Mac?

Windows

Are you running on a CI Server? If so, which one?

No.

How Did You Get This To Happen? (Steps to Reproduce)

[Edit: The code below is incorrect. See this comment for the correction.]

string mytext = "hello";
Action myaction;

// local block
{
  myaction = () =>
  {
    var t = mytext;  // NullReferenceException
  }
}

myaction();

A NullReferenceException is thrown since this captured in the closure is null for some reason.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

@patriksvensson: Seems there is a similar bug in Roslyn: https://github.com/dotnet/roslyn/issues/16895

Should I file a new issue there?