1

Getting Exception using Code on Thread.

Hello,

there is already a cool thread about this question I wanted to use, but i can't post a comment because I do not have a reputation of 50. So I needed to create a new Thread (which seems ridiculous for me...). I didn't want to post my question as an answer because that seems wrong to me. The thread I wanted to post on: How do I use Assert.Throws to assert the type of the exception?

My Problem: I'm using exactly the code demonstrated as answer, but I'm getting an Error: "NullReferenceException is a type and not valid in this context"

Here My Code:

if (toSort == null)
{
    Assert.Throws<NullReferenceException>(() => { HeapSort.Sort(toSort); });
}

I'm very thankful for your time and help.

Best regards!

Gino Pensuni
  • 356
  • 4
  • 15
  • 1
    Looks correct to me. Do you have your own implementation of any of the involved type names? Are you sure the error is on this particular line? – PMF Jan 03 '19 at 19:18
  • Okay, Now I think thats black magic! I made a pause of 30 minutes, came back, added a space after the end curly bracket of the if statement and the error vanished! Pff... – Gino Pensuni Jan 03 '19 at 19:27
  • 1
    Sounds like for some reason the compiler wasn't updating the binaries properly. In rare case this happens even if the file is changed, I've mostly seen it after some source control operations changed the file and Visual Studio failed to notice that. A dummy change (such as yours) fixes it. – PMF Jan 04 '19 at 12:39

0 Answers0