Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. UserControl within a UserControl

UserControl within a UserControl

Scheduled Pinned Locked Moved C#
helpcsharpvisual-studio
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goldoche
    wrote on last edited by
    #1

    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!

    M L 2 Replies Last reply
    0
    • G goldoche

      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!

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • G goldoche

        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!

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Maybe this article[^] contains what you need, or at least provides a hint. :)

        Luc Pattyn

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups