Freelance web and mobile developer
In: .NET
26 Sep 2008A 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:
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.
I'm a freelance web and mobile developer that likes to share whatever experiences I might encounter. It used to be .NET related, and still is to large extent, but I'm also a struggling agnostic trying out interesting technologies from the big three - Microsoft, Google, Apple - and the open source world.
12 Responses to MissingMethodException and WaitOne
Vaclav Kabat
October 23rd, 2008 at 14:12
my primary issue is that both dlls (before and after) have same version
joe
January 5th, 2009 at 21:38
these new overloads stung me and I wasted many hours. they shouldn’t introduce new overloads in a service pack, if you ask me.
Michael
February 24th, 2009 at 10:18
Mike, thanks for the info! You helped me a lot.
listar
April 7th, 2009 at 05:54
Mike, thanks! I got a few hours of headache with MissingMethodException and finally I found your article! Thanks again!!! You save my day =)
Luckyrat
May 7th, 2009 at 22:48
+1
Took me a while to realise this was my problem (I am calling the method via a separate unmanaged process and with my lack of C++ expertise it was ages before I even considered it could be a .NET failure).
Thanks!
Chris
June 18th, 2009 at 16:07
+1
Wow, I spent a few hours debugging this problem, the customer had .Net framework 3.5 (not SP1) installed, it worked fine for me but not for him… I think google suggest was the biggest help, I was searching for “missingmethodexception” and it suggested that I add “waitone” to the search string, that’s how I found this article
Thanks!!!
Martin
June 30th, 2009 at 15:02
Thanks Mike, this saved me a lot of time.
It seems to me that the “multi-targeting” feature of VS2008 is somewhat broken. I ask it to target v2.0 of the .NET framework, and it allows me to write code that only works in a version of v2.0 that’s deployed with v3.5.
Peter Stephens
July 28th, 2009 at 12:27
One note: the documentation for WaitHandle.WaitOne(int) claims that it will work for .NET 2.0 SP1. This is not true as you have found out. 2.0 SP2 is required.
MissingMethodException and WaitOne « Second Stanza
August 1st, 2009 at 17:59
[...] .NET Development — dfbaskin @ 12:59 pm I ran into the same problem as Mike Plate describes here. Fortunately, there is a now separate download for the .NET 2.0 Service Pack 2 here. Installing [...]
DJacobs
August 27th, 2009 at 19:13
FWIW, I had a P9 system.missingmethodexception error that was crashing a simple application on some machines but not on others. I tracked it down to a “.WaitOne(2000)” line that was executing inside a thread. Never causes a problem on my machine, but it sure crashed on those other machines, EVEN THOUGH THE CODE WAS NEVER EXECUTED! The thread hadn’t even gotten to that line. The crash was occurring when the program started up, which was really frustrating. I even had a “try..catch” around the problem line of code, and it didn’t help. I stopped using the AutoResetEvent and used a variable and a “while( ! signaled ) { Thread.sleep(20); }, which was a kludge, but it worked….
DJacobs
September 8th, 2009 at 19:07
Apparently, this error is thrown by the JIT compiler, which is why no amount of “try..catch” lines will prevent it: http://stackoverflow.com/questions/809337/net-wpf-missingmethodexception-when-launching-new-thread
DavidB
July 26th, 2010 at 21:11
Another vote of thanks.
I wasn’t even getting the ‘Method Not Found’ error until I put some error handling in the thread constructor:
Thread myThread = new Thread(() =>
{
try
{
MyWaitOneMethod();
}
catch (Exception ex)
{
// Error logging code
}
});