Friday, July 24, 2009

Setup Error

I have been working on this stupid bug like all week: one of my programs would occaisionally pop up a window entitled "Setup Error," with the contents "Failed to load resources from resource file. Please check your Setup" and then disappear when the window was dismissed: no exceptions to catch, no other clue as to what might be wrong.

It's evidently a symptom that can arise under several different circumstances: I found several people who saw it when causing an infinite recursion, or when running an application on a machine with certain third-party anti-virus software installed. I didn't find anything that sounded like my circumstances, so I record them here in hopes that frustrated searchers might be helped along.

My setup and architecture were as follows:

  • .NET Framework 1.1;
  • One UI event handler hides the main form and creates another form, displayed in its own Get/Translate/Dispatch message loop until it's closed;
  • The new form creates a System.Windows.Forms timer;
  • At which point, certain calls (the two I found were System.Threading.Thread.Start() and the overloaded System.Xml.XmlDocument.Load() that takes a URI string; the one taking a TextReader worked fine) cause the "Setup Error" when made from the timer elapsed event handler.
Also, the "Setup Error" only occurred when running a Release build, either from Windows or from Visual Studio "Without Debugging."

I'm still not sure exactly what I was doing wrong, or whether I was encountering a bug in the framework. I refactored the code to get rid of my inner message loop and it seems to have fixed things, so I assume that the implementation of the forms timer somehow relies on its only being maintained by the built-in message loop...but in such a way that causes only certain other methods to fail? It's a mystery.

No comments: