By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

terrible annoying BUG in VS.NET 2005 with UserControl at DesignTime?!

P: n/a
Hi,

I'm getting a really terrible and anoying bug/problem in VS.NET 2005:

1. Create a new Windows Application.
2. Add a new class Class1.
3. Add a usercontrol UserControl1.
4. Add a public instance of Class1 to UserControl1 (with WithEvents):
"Public WithEvents ThisClass As New Class1".
5. Build the Solution, and put an instance of UserControl1 on Form1.
6. Rebuild the Solution, and open the Form1 in the Designer (View Designer)
-> Everything works fine, you can close it and open it again in the designer
as much as you want...

7. Change anything to Form1 in the Designer: for instance make it just a
tiny bit larger. Save the changes, and close the Form1.
-> When you nowwant to open Form1 in the Designer, you get some nasty
exception:
*****************
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 type 'WindowsApplication1.UserControl1' has no field named 'ThisClass'.
Hide Edit

at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeAssignStatement(IDesigne rSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeStatement(IDesignerSeria lizationManager
manager, CodeStatement statement)

****************

I noticed it added in the Form1.Designer.vb some lines in the
InitializeComponent():
"Dim Class11 As WindowsApplication1.Class1 = New WindowsApplication1.Class1"
and a little bit further "Me.UserControl11.ThisClass = Class11".
You can't open Form1 in the Designer if you don't remove the second line...

This behaviour doesn't happen if you declare the instance ThisClass as
Private, or without the WithEvents...

But I really would like to have it Public WithEvents. And I can't stand it
that I can't, hehe. Does anybody knows a solution for this? Is this a Bug?
Or is there a rule that a UserControl can't containt Public WithEvents
classes??

Any help, hints, or whatever would be really appreciated!
Thanks a lot in advance,

Pieter


Nov 25 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

Hey Pieter,

you can best report this bug on the following link:

http://lab.msdn.microsoft.com/produc...k/default.aspx

you can also look if the same bug has already been reported and see if there
is a work around.

if this post is helpfull click on yes on the bottom of the post :-p
"Pieter" wrote:
Hi,

I'm getting a really terrible and anoying bug/problem in VS.NET 2005:

1. Create a new Windows Application.
2. Add a new class Class1.
3. Add a usercontrol UserControl1.
4. Add a public instance of Class1 to UserControl1 (with WithEvents):
"Public WithEvents ThisClass As New Class1".
5. Build the Solution, and put an instance of UserControl1 on Form1.
6. Rebuild the Solution, and open the Form1 in the Designer (View Designer)
-> Everything works fine, you can close it and open it again in the designer
as much as you want...

7. Change anything to Form1 in the Designer: for instance make it just a
tiny bit larger. Save the changes, and close the Form1.
-> When you nowwant to open Form1 in the Designer, you get some nasty
exception:
*****************
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 type 'WindowsApplication1.UserControl1' has no field named 'ThisClass'.
Hide Edit

at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeAssignStatement(IDesigne rSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeStatement(IDesignerSeria lizationManager
manager, CodeStatement statement)

****************

I noticed it added in the Form1.Designer.vb some lines in the
InitializeComponent():
"Dim Class11 As WindowsApplication1.Class1 = New WindowsApplication1.Class1"
and a little bit further "Me.UserControl11.ThisClass = Class11".
You can't open Form1 in the Designer if you don't remove the second line...

This behaviour doesn't happen if you declare the instance ThisClass as
Private, or without the WithEvents...

But I really would like to have it Public WithEvents. And I can't stand it
that I can't, hehe. Does anybody knows a solution for this? Is this a Bug?
Or is there a rule that a UserControl can't containt Public WithEvents
classes??

Any help, hints, or whatever would be really appreciated!
Thanks a lot in advance,

Pieter


Nov 25 '05 #2

P: n/a
Didn't find a similar bug, and posted it :-)

"interwanderer" <in***********@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...

Hey Pieter,

you can best report this bug on the following link:

http://lab.msdn.microsoft.com/produc...k/default.aspx

you can also look if the same bug has already been reported and see if
there
is a work around.

if this post is helpfull click on yes on the bottom of the post :-p

Nov 25 '05 #3

P: n/a
On Fri, 25 Nov 2005 09:23:08 +0100, Pieter wrote:
Hi,

I'm getting a really terrible and anoying bug/problem in VS.NET 2005:

1. Create a new Windows Application.
2. Add a new class Class1.
3. Add a usercontrol UserControl1.
4. Add a public instance of Class1 to UserControl1 (with WithEvents):
"Public WithEvents ThisClass As New Class1".
5. Build the Solution, and put an instance of UserControl1 on Form1.
6. Rebuild the Solution, and open the Form1 in the Designer (View Designer)
-> Everything works fine, you can close it and open it again in the designer
as much as you want...

7. Change anything to Form1 in the Designer: for instance make it just a
tiny bit larger. Save the changes, and close the Form1.
-> When you nowwant to open Form1 in the Designer, you get some nasty
exception:
*****************
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 type 'WindowsApplication1.UserControl1' has no field named 'ThisClass'.
Hide Edit

at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeAssignStatement(IDesigne rSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeStatement(IDesignerSeria lizationManager
manager, CodeStatement statement)

****************

I noticed it added in the Form1.Designer.vb some lines in the
InitializeComponent():
"Dim Class11 As WindowsApplication1.Class1 = New WindowsApplication1.Class1"
and a little bit further "Me.UserControl11.ThisClass = Class11".
You can't open Form1 in the Designer if you don't remove the second line...

This behaviour doesn't happen if you declare the instance ThisClass as
Private, or without the WithEvents...

But I really would like to have it Public WithEvents. And I can't stand it
that I can't, hehe. Does anybody knows a solution for this? Is this a Bug?
Or is there a rule that a UserControl can't containt Public WithEvents
classes??

Any help, hints, or whatever would be really appreciated!
Thanks a lot in advance,

Pieter


Well, it does appear to be a bug or confusion by the designer for VB.Net,
but it's also a rather messy way of doing things.

A more correct way to implement this type of feature is to use something
like:
Public Class UserControl1
Private _ThisClass As New Class1()
Public ReadOnly Property ThisClass() As Class1
Get
Return _ThisClass
End Get
End Property
End Class

There is no point in having WithEvents on the declaration unless you plan
to handle the events in the usercontrol itself. If so, just add WithEvents
to the definition of _ThisClass and add 'Handles _ThisClass.xxx' in your
UserControl.
If you want to intercept Class1's events from outside of the UserControl
then you have to use something like:

Private Sub Form1_Load(...) Handles MyBase.Load
AddHandler (Me.UserControl11.ThisClass).TestClick, AddressOf doit
:
:

Private Sub doit()
MessageBox.Show("Hi!")
End Sub

but it's better to add your own events to the UserControl and ripple them
down from the embedded object.

The reason you have to wrap the Class1 object in a ReadOnly property is to
prevent it being serialized and initialised in the Form1.Designer.vb class.

Cheers,
Jason
Nov 25 '05 #4

P: n/a
On Fri, 25 Nov 2005 09:23:08 +0100, Pieter wrote:
Hi,

I'm getting a really terrible and anoying bug/problem in VS.NET 2005:

1. Create a new Windows Application.
2. Add a new class Class1.
3. Add a usercontrol UserControl1.
4. Add a public instance of Class1 to UserControl1 (with WithEvents):
"Public WithEvents ThisClass As New Class1".
5. Build the Solution, and put an instance of UserControl1 on Form1.
6. Rebuild the Solution, and open the Form1 in the Designer (View Designer)
-> Everything works fine, you can close it and open it again in the designer
as much as you want...

7. Change anything to Form1 in the Designer: for instance make it just a
tiny bit larger. Save the changes, and close the Form1.
-> When you nowwant to open Form1 in the Designer, you get some nasty
exception:
*****************
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 type 'WindowsApplication1.UserControl1' has no field named 'ThisClass'.
Hide Edit

at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeAssignStatement(IDesigne rSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeStatement(IDesignerSeria lizationManager
manager, CodeStatement statement)

****************

I noticed it added in the Form1.Designer.vb some lines in the
InitializeComponent():
"Dim Class11 As WindowsApplication1.Class1 = New WindowsApplication1.Class1"
and a little bit further "Me.UserControl11.ThisClass = Class11".
You can't open Form1 in the Designer if you don't remove the second line...

This behaviour doesn't happen if you declare the instance ThisClass as
Private, or without the WithEvents...

But I really would like to have it Public WithEvents. And I can't stand it
that I can't, hehe. Does anybody knows a solution for this? Is this a Bug?
Or is there a rule that a UserControl can't containt Public WithEvents
classes??

Any help, hints, or whatever would be really appreciated!
Thanks a lot in advance,

Pieter


Well, it does appear to be a bug or confusion by the designer for VB.Net,
but it's also a rather messy way of doing things.

A more correct way to implement this type of feature is to use something
like:
Public Class UserControl1
Private _ThisClass As New Class1()
Public ReadOnly Property ThisClass() As Class1
Get
Return _ThisClass
End Get
End Property
End Class

There is no point in having WithEvents on the declaration unless you plan
to handle the events in the usercontrol itself. If so, just add WithEvents
to the definition of _ThisClass and add 'Handles _ThisClass.xxx' in your
UserControl.
If you want to intercept Class1's events from outside of the UserControl
then you have to use something like:

Private Sub Form1_Load(...) Handles MyBase.Load
AddHandler (Me.UserControl11.ThisClass).TestClick, AddressOf doit
:
:

Private Sub doit()
MessageBox.Show("Hi!")
End Sub

but it's better to add your own events to the UserControl and ripple them
down from the embedded object.

The reason you have to wrap the Class1 object in a ReadOnly property is to
prevent it being serialized and initialised in the Form1.Designer.vb class.

Cheers,
Jason
Nov 25 '05 #5

P: n/a
On Fri, 25 Nov 2005 09:23:08 +0100, Pieter wrote:
Hi,

I'm getting a really terrible and anoying bug/problem in VS.NET 2005:

1. Create a new Windows Application.
2. Add a new class Class1.
3. Add a usercontrol UserControl1.
4. Add a public instance of Class1 to UserControl1 (with WithEvents):
"Public WithEvents ThisClass As New Class1".
5. Build the Solution, and put an instance of UserControl1 on Form1.
6. Rebuild the Solution, and open the Form1 in the Designer (View Designer)
-> Everything works fine, you can close it and open it again in the designer
as much as you want...

7. Change anything to Form1 in the Designer: for instance make it just a
tiny bit larger. Save the changes, and close the Form1.
-> When you nowwant to open Form1 in the Designer, you get some nasty
exception:
*****************
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 type 'WindowsApplication1.UserControl1' has no field named 'ThisClass'.
Hide Edit

at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeAssignStatement(IDesigne rSerializationManager
manager, CodeAssignStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDom SerializerBase.DeserializeStatement(IDesignerSeria lizationManager
manager, CodeStatement statement)

****************

I noticed it added in the Form1.Designer.vb some lines in the
InitializeComponent():
"Dim Class11 As WindowsApplication1.Class1 = New WindowsApplication1.Class1"
and a little bit further "Me.UserControl11.ThisClass = Class11".
You can't open Form1 in the Designer if you don't remove the second line...

This behaviour doesn't happen if you declare the instance ThisClass as
Private, or without the WithEvents...

But I really would like to have it Public WithEvents. And I can't stand it
that I can't, hehe. Does anybody knows a solution for this? Is this a Bug?
Or is there a rule that a UserControl can't containt Public WithEvents
classes??

Any help, hints, or whatever would be really appreciated!
Thanks a lot in advance,

Pieter


Well, it does appear to be a bug or confusion by the designer for VB.Net,
but it's also a rather messy way of doing things.

A more correct way to implement this type of feature is to use something
like:
Public Class UserControl1
Private _ThisClass As New Class1()
Public ReadOnly Property ThisClass() As Class1
Get
Return _ThisClass
End Get
End Property
End Class

There is no point in having WithEvents on the declaration unless you plan
to handle the events in the usercontrol itself. If so, just add WithEvents
to the definition of _ThisClass and add 'Handles _ThisClass.xxx' in your
UserControl.
If you want to intercept Class1's events from outside of the UserControl
then you have to use something like:

Private Sub Form1_Load(...) Handles MyBase.Load
AddHandler (Me.UserControl11.ThisClass).TestClick, AddressOf doit
:
:

Private Sub doit()
MessageBox.Show("Hi!")
End Sub

but it's better to add your own events to the UserControl and ripple them
down from the embedded object.

The reason you have to wrap the Class1 object in a ReadOnly property is to
prevent it being serialized and initialised in the Form1.Designer.vb class.

Cheers,
Jason
Nov 26 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.