- Joined
- Sep 26, 2006
- Messages
- 1
- Reaction score
- 0
Introduction
This post describes and presents a workaround for the following bug:
Every time you open a form it keeps reporting the following erro, even after rebuild:
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.
The variable 'VariableName' is either undeclared or was never assigned.
Buggy Scenario (simplified declaration) – This causes the Undeclared Bug
Workaround Scenario (simplified declaration) – This works fine
If want to see it in action, run the attached sample.
Sample
Run this sample View attachment Vb2005Bug-TheVariableIsEitherUndeclaredOrWasNeverAssigned.zip, rebuild it and compare both versions, the good one and the bad one.
In this sample there are two forms: The WorkingForm and the BuggyForm.
Both forms contain a custom user control which is composed by a Button and a public property named PersonObject of Person type.
The only difference between the WorkingForm and the BuggyForm is the location where PersonObject’s type is defined.
The WorkingForm uses a button which PersonObject references a Person class defined at namespace level. See the WorkingCustomButton and WorkingNameSpace.
The BuggyForm uses a button which PersonObject references a Person class defined at class level. See the BuggyCustomButton and BuggyNameSpace.
This happens, although both definitions have public-scope.
Conclusion
Identify every class referenced by the user control class and declare the ones declared at a class-level at namespace level.
I hope this post saves you some headaches guys, at least untill Microsoft gets it fixed.
By the way, let me know how to deliver this bug-proof sample to VS DevTeam.
Júlio Nobre
This post describes and presents a workaround for the following bug:
Every time you open a form it keeps reporting the following erro, even after rebuild:
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.
The variable 'VariableName' is either undeclared or was never assigned.
Buggy Scenario (simplified declaration) – This causes the Undeclared Bug
Code:
Namespace MyNameSpace
Public Class MyUserControl
Public Property ObjMyClass as New MyNameSpace.MyUserControl.MyClass (using a TypeConverter)
Public Class MyClass
<ClassBody>
End class
End class
End namespace
Workaround Scenario (simplified declaration) – This works fine
Code:
Namespace MyNameSpace
Public Class MyUserControl
Public Property ObjMyClass as New MyNameSpace.MyClass (using a TypeConverter)
End class
Public Class MyClass
<ClassBody>
End class
End namespace
If want to see it in action, run the attached sample.
Sample
Run this sample View attachment Vb2005Bug-TheVariableIsEitherUndeclaredOrWasNeverAssigned.zip, rebuild it and compare both versions, the good one and the bad one.
In this sample there are two forms: The WorkingForm and the BuggyForm.
Both forms contain a custom user control which is composed by a Button and a public property named PersonObject of Person type.
The only difference between the WorkingForm and the BuggyForm is the location where PersonObject’s type is defined.
The WorkingForm uses a button which PersonObject references a Person class defined at namespace level. See the WorkingCustomButton and WorkingNameSpace.
The BuggyForm uses a button which PersonObject references a Person class defined at class level. See the BuggyCustomButton and BuggyNameSpace.
This happens, although both definitions have public-scope.
Conclusion
Identify every class referenced by the user control class and declare the ones declared at a class-level at namespace level.
I hope this post saves you some headaches guys, at least untill Microsoft gets it fixed.
By the way, let me know how to deliver this bug-proof sample to VS DevTeam.
Júlio Nobre