473,715 Members | 5,945 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 'WindowsApplica tion1.UserContr ol1' has no field named 'ThisClass'.
Hide Edit

at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Error(IDes ignerSerializat ionManager
manager, String exceptionText, String helpLink)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eAssignStatemen t(IDesignerSeri alizationManage r
manager, CodeAssignState ment statement)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eStatement(IDes ignerSerializat ionManager
manager, CodeStatement statement)

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

I noticed it added in the Form1.Designer. vb some lines in the
InitializeCompo nent():
"Dim Class11 As WindowsApplicat ion1.Class1 = New WindowsApplicat ion1.Class1"
and a little bit further "Me.UserControl 11.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
5 1517

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 'WindowsApplica tion1.UserContr ol1' has no field named 'ThisClass'.
Hide Edit

at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Error(IDes ignerSerializat ionManager
manager, String exceptionText, String helpLink)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eAssignStatemen t(IDesignerSeri alizationManage r
manager, CodeAssignState ment statement)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eStatement(IDes ignerSerializat ionManager
manager, CodeStatement statement)

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

I noticed it added in the Form1.Designer. vb some lines in the
InitializeCompo nent():
"Dim Class11 As WindowsApplicat ion1.Class1 = New WindowsApplicat ion1.Class1"
and a little bit further "Me.UserControl 11.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
Didn't find a similar bug, and posted it :-)

"interwande rer" <in***********@ discussions.mic rosoft.com> wrote in message
news:4D******** *************** ***********@mic rosoft.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
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 'WindowsApplica tion1.UserContr ol1' has no field named 'ThisClass'.
Hide Edit

at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Error(IDes ignerSerializat ionManager
manager, String exceptionText, String helpLink)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eAssignStatemen t(IDesignerSeri alizationManage r
manager, CodeAssignState ment statement)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eStatement(IDes ignerSerializat ionManager
manager, CodeStatement statement)

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

I noticed it added in the Form1.Designer. vb some lines in the
InitializeCompo nent():
"Dim Class11 As WindowsApplicat ion1.Class1 = New WindowsApplicat ion1.Class1"
and a little bit further "Me.UserControl 11.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.UserControl 11.ThisClass).T estClick, 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
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 'WindowsApplica tion1.UserContr ol1' has no field named 'ThisClass'.
Hide Edit

at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Error(IDes ignerSerializat ionManager
manager, String exceptionText, String helpLink)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eAssignStatemen t(IDesignerSeri alizationManage r
manager, CodeAssignState ment statement)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eStatement(IDes ignerSerializat ionManager
manager, CodeStatement statement)

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

I noticed it added in the Form1.Designer. vb some lines in the
InitializeCompo nent():
"Dim Class11 As WindowsApplicat ion1.Class1 = New WindowsApplicat ion1.Class1"
and a little bit further "Me.UserControl 11.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.UserControl 11.ThisClass).T estClick, 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
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 'WindowsApplica tion1.UserContr ol1' has no field named 'ThisClass'.
Hide Edit

at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Error(IDes ignerSerializat ionManager
manager, String exceptionText, String helpLink)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eAssignStatemen t(IDesignerSeri alizationManage r
manager, CodeAssignState ment statement)
at
System.Componen tModel.Design.S erialization.Co deDomSerializer Base.Deserializ eStatement(IDes ignerSerializat ionManager
manager, CodeStatement statement)

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

I noticed it added in the Form1.Designer. vb some lines in the
InitializeCompo nent():
"Dim Class11 As WindowsApplicat ion1.Class1 = New WindowsApplicat ion1.Class1"
and a little bit further "Me.UserControl 11.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.UserControl 11.ThisClass).T estClick, 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1073
by: João Santa Bárbara | last post by:
Hi all, i´m doing a user control, and one of my public properties is a collection, but in designtime, i´m adding a few objects of my type, but none of them are saved in the form, everytime i go to the properties of my object nothing is in there ? anyone have a sample or counld help me ?? thks JSB
0
1268
by: stew_mclean | last post by:
Hi, I've developed a class that derives from component (rather than a control), and am trying to license it at design time. I've set the license attributes etc. to my custom license provider: The problem is that my license provider never gets called at designtime. To prove this, I've put this code into the implementation
2
1995
by: Jim | last post by:
I have some complex (fairly) user controls that I have created. Some of those user controls host other user controls. When I host one of these on a WinForm, I sometimes run into problems where the designer blows up with an "Object Reference Not Set to an Instance of an Object". Sometimes it even (so kindly) "munches" my code in the hosting control. Unfortunately, it seldm if ever tlss "where" exactly the problem occurred, and to my...
2
2062
by: Able | last post by:
Dear friends I have placed a Listbox on a Usercontrol. How do I move the Listbox to upper left corner and make the listbox same size as usercontrol when resizing usercontrol in designtime? Regards Able
5
1229
by: Pieter | last post by:
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.
2
5066
by: Steve | last post by:
This is a weird one. I have a series of "SmartParts" which are CAB (Composite Application Block) Views which are finally just UserControls (99% of the time) Anyway, I layout my UserControl in the VS2005 designer, but at runtime, the controls are in different locations and different sizes. I have been able to restore their sizes by putting a hack together that will set their sizes to the correct values in the UserControl's Resize...
1
3004
by: bonk | last post by:
I have a very simple UserControl (derived from System.Windows.Forms.UserControl) that contains several ListViews. The UserControl exposes a single public property: public ListView.ColumnHeaderCollection Columns { get {...} }; When I use VS2005 designer's proprtygrid for that UserConrol to add new Colums to the Collection everything works fine: The form that contains the UserControl gets new members ( private...
7
2497
by: Coleen | last post by:
Does anyone have any good detailed information on the conversion process? We are in the process of converting 2 projects from 2003 to 2005 and have some conversion errors that I can not find answers to. First, we have a lot of UserControls. I am getting the error "Type uc_mc_btn_footer is not defined." where uc_mc_btn_footer is the name of the UserControl. Also, on almost all of our UserControls the conversion has remmed out all my code...
5
1450
by: billsahiker | last post by:
I saw one post here that basically said no way, but not sure which vs version was being discussed. Using vs 2005 I develped a user control in a vb project and would like to use that usercontrol in a web app, also developed with vs2005. I tried using @Reference and put the dll in the bin folder, and when that failed I created a Contols folder and put it there and still no luck. Intuitively it makes sense that this does not work, since vb...
0
8718
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9340
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9103
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5967
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.