Visual Studio and forms resources

Tuesday, July 11, 2006 0 Comments

This is one of those "undocumented" and curious behavoirs of visual studio. To begin with, VS 2003 creates two different files to define a winform, one .cs, one .resx containing the resources. How these resources get compiled into the executable was kind of obscure to me, resulting that, in normal conditions, resources are prefixed with the namespace of the winform. Nothing new, uh?

But here comes the surprise: not in all cases. We had two forms that where getting their resources compiled with the default namespace of the project instead of the namespace of the form, causing a resource load exception, of course.

Everything becomes dark when one tries to find where this behavoir is defined, as no property defines that looks minimally related.

The problem was that these two forms had an enumeration declared before the form class in the .cs file

public namespace samplenamespace
public enum sdfsdf {}

public class MyForm: System.Windows.Forms.Form {}


Visual studio does warn you that the first element in the class
file should be the form. Indeed, if you declare a different class before the
form class, the designer stops drawing the form, and tells you about it, but
with the enum, nothing is advised. The only effect is it will prefix
resources in a different (usually wrong) way.

0 comentarios: