dotnet

Tag Archive

MissingMethodException and WaitOne

A customer complained today about a WinForms application written for .NET 2.0 that crashed. It turns out that on the customer's computer, a MissingMethodException is thrown when calling:

bool signal = WaitHandle.WaitOne(0);
Well, it works fine on my computer and I was certain that the project settings in Visual Studio 2008 was set to .NET version 2.0 and that the customer has that version of .NET installed. It is a system method, so it should be there, shouldn't it? Not so. Turns out, if I'm not mistaken here, that this a new overload of the WaitOne method that was introduced in .NET 2.0 SP2. There are several overloads of this method, and the two I was having trouble choosing between was:
bool WaitOne(int millisecondsTimeout, bool exitContext); bool WaitOne(int millisecondsTimeout);
I must confess that I'm not entirely sure what exitContext means and the difference in supplying true or false. So out of laziness, when Visual Studio presented me with these choices, I chose the latter without the bool argument. Bad choice! From what I understand this overload was actually added in .NET Framework 2.0 Service Pack 2. However it seems that SP2 is not installed by Windows Update and isn't even available as a separate download. It is only available as part of .NET Framework 3.5 Service Pack 1. You might know about the confusion about .NET Framework versions that seems to have replaced the old COM based dll hell. I'm probably not the best person to explain it and I sure use my own terminology. However, I'm going to give it a shot: The thing is that one differentiates between the "core" .NET and "extensions" to .NET. Since version 3.0 of .NET no new versions has been created for the "core". All libraries from version 3.0 and up are "extensions" and they all depend on the "core". The "core" .NET is therefore still in version 2.0. However, I guess some bugs might have been discovered but also I'm guessing that while building the "extensions" a need for some updates in the "core" arised, which is why the "core" still had to be changed. And this lead to the release of service packs for the "core". The result is that the package known as ".NET 3.5 SP1" includes an update to the core known as ".NET 2.0 SP2". Anyway, there are two "fixes" for my problem:
  • Supply a boolean as the second argument to WaitOne in all my code.
  • Require .NET 3.5 SP1 to run the application.
I chose the first one. To Visual Studio, one might request that you had warned me about this. There is a generation of warnings when building applications where you use certain classes and methods that "should not be used anymore". I guess this is the opposite, but should still warrant a warning? Note: Please make a comment if you have a better understanding of this issue than I have. I can't say I have verified all my findings. Read more...

2008-09-26
Twitter: @mikeplate