BDS 2006, WinForms applications and missing resource file problem
Posted: (EET/GMT+2)
After downloading and installing Borland Developer Studio 2006 Update 2 (Delphi 2006 Update 2), I thought I'd recompile an old .NET 1.1 WinForms application that I wrote with BDS 2005.
When you open an older project with BDS 2006, it is clever enough to convert your assembly references for the 2006 release (BDS 4.0 internally). This step goes nicely, but one I played around a bit with my application, I suddenly started to get these error messages when pressing F9 to run the application:
Project MyDelphiProject.exe encountered unhandled exception class System.Resources.MissingManifestResourceException with message 'Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "QueryForm.resources" was correctly embedded or linked into assembly "MyDelphiProject".
Now, I recall running into this problem earlier already with Delphi 2005, but then I thought it was just an user error. However, now I managed to run into the same problem many times, and thus I want to show you the workaround. (I'm still unable to exactly reproduce the problem, but it will happen with WinForms applications.)
The problem occurs because Delphi somehow truncates your resource file references in your project's .DPR file. For each WinForm in your application, there should be an $R directive with the following format:
{$R 'unit.form-class-name.resources' 'unit.resx'}
However, for some reason, Delphi sometimes truncates these to simply:
{$R 'unit.resources' 'unit.resx'}
That is, the name of WinForms class is left out. If this happens, your project will not either compile and/or will refuse to run. To fix it, simply return the $R directives to their prior state.