question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullReferenceException in closure

See original GitHub issue

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.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
peter-perotcommented, Feb 2, 2017

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

Should I file a new issue there?

0reactions
devleadcommented, Nov 3, 2017

@peter-perot @wozzo this is now sorted without need for experimental as we unified around a newer version of Roslyn since 0.22.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullReferenceException on closing datareader
Close () an exception that says NullRefferenceException. What am I doing wrong? EDIT. I just noticed that reader = cmd.ExecuteReader(); throws an ...
Read more >
How to solve this problem: RemoteException wrapping ...
NullReferenceException: Object reference not set to an instance of an object. at lambda_method(Closure , ActivityContext ) at Microsoft.
Read more >
How can I fix the error: System.NullReferenceException
A NullReferenceException exception is thrown when you try to access a member on a type whose value is null. A NullReferenceException exception ...
Read more >
Null reference exception in the close function - Dispose ...
I am using dispose pattern to clear Postgresql resources. Occasionally following exception is thrown. Do you have ideas what can cause this ...
Read more >
NullReferenceException when close connection #2143
Exception message: Object reference not set to an instance of an object. Stack trace: at Npgsql.NpgsqlConnection.Close(Boolean wasBroken) at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found