Monitor.Enter: No overload for method takes 2 arguments

I recently inherited some code that I can't get to build yet. Here's the offending line:

Monitor.Enter(this.foo, ref lockTaken);

According to Visual Studios there is only one definition and it takes a single argument but according to MSDN the two argument version should exist. Any idea how to resolve this?

Thanks.

Jon Skeet
people
quotationmark

That overload was introduced in .NET 4. So as you were targeting .NET 2.0, it wasn't present.

When in doubt, check the "Version information" section at the bottom of the documentation.

Admittedly I'd normally be at least slightly nervous about manual calls to Monitor.Enter/Exit anyway - in 99% of cases, using lock is a better idea.

people

See more on this question at Stackoverflow