UserControl within a UserControl
-
Hi, I have a very frustrating problem. I have this UserControl I use on a Form. This UserControls is nothing complicated: buttons, textboxes, etc. When I start my application, everything works fine. When I add another (simple) UserControl to my first UserControl, everything works fine too... well almost everything. The application starts and works 100%, but when I close it and go back to the Designer of my main application, Visual Studio says that: "An exception occurred while trying to create an instance of MyProject.MyUserControl. The exception was "Object type cannot be converted to target type."." I seems that the Designer creates an instance of every control on the Form and this particular UserControls cannot be created properly. I really need some help, this is going to drive me nuts! I've spent more than two days on this problem!
-
Hi, I have a very frustrating problem. I have this UserControl I use on a Form. This UserControls is nothing complicated: buttons, textboxes, etc. When I start my application, everything works fine. When I add another (simple) UserControl to my first UserControl, everything works fine too... well almost everything. The application starts and works 100%, but when I close it and go back to the Designer of my main application, Visual Studio says that: "An exception occurred while trying to create an instance of MyProject.MyUserControl. The exception was "Object type cannot be converted to target type."." I seems that the Designer creates an instance of every control on the Form and this particular UserControls cannot be created properly. I really need some help, this is going to drive me nuts! I've spent more than two days on this problem!
Hello, I also had a lot of bad days because of that. 1) What you can try is, copy the dll or exe (where your second usercontrol is in) to a temp file and then ad the control in he designer over that dll. I think the problem is some kind of circular dependences between the usercontrols. In worst case you could try to export the second control in a seperat project(dll) and try it again. 2) An other posibility is that your second usercontrol throws an exeption. Therefore you could start a second instance of your design application (VS or something) and connect to the first. Then you have to change the settings, that you jump in the debugger if an exception occurs. Hope it helps. All the best, Martin
-
Hi, I have a very frustrating problem. I have this UserControl I use on a Form. This UserControls is nothing complicated: buttons, textboxes, etc. When I start my application, everything works fine. When I add another (simple) UserControl to my first UserControl, everything works fine too... well almost everything. The application starts and works 100%, but when I close it and go back to the Designer of my main application, Visual Studio says that: "An exception occurred while trying to create an instance of MyProject.MyUserControl. The exception was "Object type cannot be converted to target type."." I seems that the Designer creates an instance of every control on the Form and this particular UserControls cannot be created properly. I really need some help, this is going to drive me nuts! I've spent more than two days on this problem!
Maybe this article[^] contains what you need, or at least provides a hint. :)
Luc Pattyn