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. Null error when adding custom control

Null error when adding custom control

Scheduled Pinned Locked Moved C#
csharphelpquestion
10 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.
  • K Offline
    K Offline
    KingTermite
    wrote on last edited by
    #1

    Hi. I'm a relative newbie with C#...I have some custom controls that are snarfed code from a co-worker (the only other C# code in our workplace). I have created a windows control library project, added the code to it, and compiled it to the dll. Now I have gone to the custom controls and added them to the pane by selecting the dll file. But when I try to drag the control on to the form it gives me an error: An exception occured while trying to create an instance of CTSSExp.Controls.ExplorerControl. The exception was "null" is not a valid value for 'control.'". CTSSExp.Controls is the namespace the control is in and ExplorerControl is the name of the control. Any suggestions? Thanks.


    There are only 10 types of people in this world....those that understand binary, and those that do not.

    C 1 Reply Last reply
    0
    • K KingTermite

      Hi. I'm a relative newbie with C#...I have some custom controls that are snarfed code from a co-worker (the only other C# code in our workplace). I have created a windows control library project, added the code to it, and compiled it to the dll. Now I have gone to the custom controls and added them to the pane by selecting the dll file. But when I try to drag the control on to the form it gives me an error: An exception occured while trying to create an instance of CTSSExp.Controls.ExplorerControl. The exception was "null" is not a valid value for 'control.'". CTSSExp.Controls is the namespace the control is in and ExplorerControl is the name of the control. Any suggestions? Thanks.


      There are only 10 types of people in this world....those that understand binary, and those that do not.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      yeah - try to avoid cut and paste coding, it leads to errors. Also, avoid the form designer, that's not programming, and the designer really screws with your aspx HTML, sometimes making it invalid and often making it unreadable. You should put the custom control into a project and use it from that project in order to eliminate any errors, then try putting it into a dll. That way, you are establishing that it works one step at a time. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      K 1 Reply Last reply
      0
      • C Christian Graus

        yeah - try to avoid cut and paste coding, it leads to errors. Also, avoid the form designer, that's not programming, and the designer really screws with your aspx HTML, sometimes making it invalid and often making it unreadable. You should put the custom control into a project and use it from that project in order to eliminate any errors, then try putting it into a dll. That way, you are establishing that it works one step at a time. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        K Offline
        K Offline
        KingTermite
        wrote on last edited by
        #3

        You are right about cut/paste coding...but in many work environments, its common practice. However, I did put it in a sperate project (control library template) which compiles (no errors) to a dll. I then add it to the form designer (add/remove and select the dll file), but when I try to get it after that (it shows up in custom controls tab on the toolbar) and drag it into the form I get that error I mentioned. I'm sure its something simple...I'm just new to controls and still do not have a "lot" of experience with Visual Studio.Net and the .Net way of doing things.


        There are only 10 types of people in this world....those that understand binary, and those that do not.

        C 1 Reply Last reply
        0
        • K KingTermite

          You are right about cut/paste coding...but in many work environments, its common practice. However, I did put it in a sperate project (control library template) which compiles (no errors) to a dll. I then add it to the form designer (add/remove and select the dll file), but when I try to get it after that (it shows up in custom controls tab on the toolbar) and drag it into the form I get that error I mentioned. I'm sure its something simple...I'm just new to controls and still do not have a "lot" of experience with Visual Studio.Net and the .Net way of doing things.


          There are only 10 types of people in this world....those that understand binary, and those that do not.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          KingTermite wrote: You are right about cut/paste coding...but in many work environments, its common practice. In workplaces populated by idiots. Seriously, if you know it's bad practice, why do it ? Are you GUARENTEED to work in that place forever ? It's just self preservation to learn to do things the best way you can. If your workplace has components it wants reuses, they should be packaged in a dll to start with, and that project should be the only place the controls are modified, via source control. KingTermite wrote: However, I did put it in a sperate project (control library template) which compiles (no errors) to a dll. So there are no compile time errors. I got that before. What does that have to do with run time ? KingTermite wrote: I then add it to the form designer Like I said, don't. The form designer is the tool of idiots. Create a form, play with the designer, then go back to your HTML and see how much it has been screwed with. KingTermite wrote: I'm sure its something simple...I'm just new to controls and still do not have a "lot" of experience with Visual Studio.Net and the .Net way of doing things. Sure - that's why I suggested a couple of steps whereby you can elimanate some factors, and some bad practices, and figure out what the problem is. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          K 1 Reply Last reply
          0
          • C Christian Graus

            KingTermite wrote: You are right about cut/paste coding...but in many work environments, its common practice. In workplaces populated by idiots. Seriously, if you know it's bad practice, why do it ? Are you GUARENTEED to work in that place forever ? It's just self preservation to learn to do things the best way you can. If your workplace has components it wants reuses, they should be packaged in a dll to start with, and that project should be the only place the controls are modified, via source control. KingTermite wrote: However, I did put it in a sperate project (control library template) which compiles (no errors) to a dll. So there are no compile time errors. I got that before. What does that have to do with run time ? KingTermite wrote: I then add it to the form designer Like I said, don't. The form designer is the tool of idiots. Create a form, play with the designer, then go back to your HTML and see how much it has been screwed with. KingTermite wrote: I'm sure its something simple...I'm just new to controls and still do not have a "lot" of experience with Visual Studio.Net and the .Net way of doing things. Sure - that's why I suggested a couple of steps whereby you can elimanate some factors, and some bad practices, and figure out what the problem is. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

            K Offline
            K Offline
            KingTermite
            wrote on last edited by
            #5

            Christian Graus wrote: In workplaces populated by idiots. Seriously, if you know it's bad practice, why do it ? Are you GUARENTEED to work in that place forever ? It's just self preservation to learn to do things the best way you can. If your workplace has components it wants reuses, they should be packaged in a dll to start with, and that project should be the only place the controls are modified, via source control. No need to be so one-sided....we are not a workplace run by idiots...in fact we are at SEI level 5. Cut/Paste IS a level of reuse. It's called salvaged reuse. We do package "planned" reuse into a dll or other such libary, but my long term intentions are to modify and likely extend this control once I've got it working in the first place. Now....what HTML are you talking about? I would skip the form designer if I knew how. I need to know how to put the control in if I'm going to do that. I was trying it from the form designer because I thought that was the proper method. Thanks for trying to help...any more detailed info would be appreciated.


            There are only 10 types of people in this world....those that understand binary, and those that do not.

            K C 2 Replies Last reply
            0
            • K KingTermite

              Christian Graus wrote: In workplaces populated by idiots. Seriously, if you know it's bad practice, why do it ? Are you GUARENTEED to work in that place forever ? It's just self preservation to learn to do things the best way you can. If your workplace has components it wants reuses, they should be packaged in a dll to start with, and that project should be the only place the controls are modified, via source control. No need to be so one-sided....we are not a workplace run by idiots...in fact we are at SEI level 5. Cut/Paste IS a level of reuse. It's called salvaged reuse. We do package "planned" reuse into a dll or other such libary, but my long term intentions are to modify and likely extend this control once I've got it working in the first place. Now....what HTML are you talking about? I would skip the form designer if I knew how. I need to know how to put the control in if I'm going to do that. I was trying it from the form designer because I thought that was the proper method. Thanks for trying to help...any more detailed info would be appreciated.


              There are only 10 types of people in this world....those that understand binary, and those that do not.

              K Offline
              K Offline
              Kentamanos
              wrote on last edited by
              #6

              I never use the form designer either. I click on the tab at the bottom that says "HTML" and go from there. It does save a lot of headaches in the long run.


              I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
              -David St. Hubbins

              1 Reply Last reply
              0
              • K KingTermite

                Christian Graus wrote: In workplaces populated by idiots. Seriously, if you know it's bad practice, why do it ? Are you GUARENTEED to work in that place forever ? It's just self preservation to learn to do things the best way you can. If your workplace has components it wants reuses, they should be packaged in a dll to start with, and that project should be the only place the controls are modified, via source control. No need to be so one-sided....we are not a workplace run by idiots...in fact we are at SEI level 5. Cut/Paste IS a level of reuse. It's called salvaged reuse. We do package "planned" reuse into a dll or other such libary, but my long term intentions are to modify and likely extend this control once I've got it working in the first place. Now....what HTML are you talking about? I would skip the form designer if I knew how. I need to know how to put the control in if I'm going to do that. I was trying it from the form designer because I thought that was the proper method. Thanks for trying to help...any more detailed info would be appreciated.


                There are only 10 types of people in this world....those that understand binary, and those that do not.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                KingTermite wrote: Now....what HTML are you talking about? Any aspx page is has a .aspx file and a .cs file. The cs file is your code behind, the aspx file is your page, containing all your HTML, including the asp: tags that denote controls. When you're in the form designer, at the bottom of the page is a 'html' tab, if you click on it, you can hand edit the files. This is definately the way to go, and you should set up your preferences to always go here instead of the designer, for the reasons I mentioned. And if it were me, I'd create a new control in a project, then copy and paste the html and C# code into it, then change the namespace of the class to match the project, and try to use the control in a page. Unless it's a server control, that's just a cs file, but I'd do the same with that. Not least is the fact that you could then set break points and step through the constructors, etc. to figure out what is going wrong. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                K 1 Reply Last reply
                0
                • C Christian Graus

                  KingTermite wrote: Now....what HTML are you talking about? Any aspx page is has a .aspx file and a .cs file. The cs file is your code behind, the aspx file is your page, containing all your HTML, including the asp: tags that denote controls. When you're in the form designer, at the bottom of the page is a 'html' tab, if you click on it, you can hand edit the files. This is definately the way to go, and you should set up your preferences to always go here instead of the designer, for the reasons I mentioned. And if it were me, I'd create a new control in a project, then copy and paste the html and C# code into it, then change the namespace of the class to match the project, and try to use the control in a page. Unless it's a server control, that's just a cs file, but I'd do the same with that. Not least is the fact that you could then set break points and step through the constructors, etc. to figure out what is going wrong. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                  K Offline
                  K Offline
                  KingTermite
                  wrote on last edited by
                  #8

                  Christian Graus wrote: Any aspx page is has a .aspx file and a .cs file. The cs file is your code behind, the aspx file is your page, containing all your HTML, including the asp: tags that denote controls. When you're in the form designer, at the bottom of the page is a 'html' tab, if you click on it, you can hand edit the files. This is definately the way to go, and you should set up your preferences to always go here instead of the designer, for the reasons I mentioned. I'll look into what you guys are talking about. Right now I don't see it...I don't see an HTML tab and there are not aspx file (there are some resx files though...maybe that's it?). Anyway...I think I figured out my problem. There are two controls that I ported (with the exception of using the form designer, I did it exactly as you described for me to do it, Christian). The control that I kept trying (thinking they were all basic controls) was actually a control that contained another control or two within it...since there was nothing there, it was throwing the null exception. I tried the other control (name didn't sound right to me for what I wanted), but actually turned out to be the control I wanted and was a basic control thus yielded no errors.


                  There are only 10 types of people in this world....those that understand binary, and those that do not.

                  C 1 Reply Last reply
                  0
                  • K KingTermite

                    Christian Graus wrote: Any aspx page is has a .aspx file and a .cs file. The cs file is your code behind, the aspx file is your page, containing all your HTML, including the asp: tags that denote controls. When you're in the form designer, at the bottom of the page is a 'html' tab, if you click on it, you can hand edit the files. This is definately the way to go, and you should set up your preferences to always go here instead of the designer, for the reasons I mentioned. I'll look into what you guys are talking about. Right now I don't see it...I don't see an HTML tab and there are not aspx file (there are some resx files though...maybe that's it?). Anyway...I think I figured out my problem. There are two controls that I ported (with the exception of using the form designer, I did it exactly as you described for me to do it, Christian). The control that I kept trying (thinking they were all basic controls) was actually a control that contained another control or two within it...since there was nothing there, it was throwing the null exception. I tried the other control (name didn't sound right to me for what I wanted), but actually turned out to be the control I wanted and was a basic control thus yielded no errors.


                    There are only 10 types of people in this world....those that understand binary, and those that do not.

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    Glad it worked out, I've worked out something too. I'm in the C# forum, not the ASP.NET forum. You therefore are probably working on a GUI app and you have no aspx files, no HTML. Sorry, my bad. Just out of curiosity, is this app for internal use only ? If not, why are you using C#, does your target audience all have the .NET runtime, or will you only distribute on CD, or do you consider the business lost to people unwilling to download the runtime to be negligible ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                    K 1 Reply Last reply
                    0
                    • C Christian Graus

                      Glad it worked out, I've worked out something too. I'm in the C# forum, not the ASP.NET forum. You therefore are probably working on a GUI app and you have no aspx files, no HTML. Sorry, my bad. Just out of curiosity, is this app for internal use only ? If not, why are you using C#, does your target audience all have the .NET runtime, or will you only distribute on CD, or do you consider the business lost to people unwilling to download the runtime to be negligible ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                      K Offline
                      K Offline
                      KingTermite
                      wrote on last edited by
                      #10

                      Christian Graus wrote: Glad it worked out, I've worked out something too. I'm in the C# forum, not the ASP.NET forum. You therefore are probably working on a GUI app and you have no aspx files, no HTML. Sorry, my bad. Yes, its a C# app....I guess that is why no aspx files. :) Christian Graus wrote: Just out of curiosity, is this app for internal use only ? If not, why are you using C#, does your target audience all have the .NET runtime, or will you only distribute on CD, or do you consider the business lost to people unwilling to download the runtime to be negligible ? This will be an internally used app, so distributing the .Net runtime will not be an issue in this case. If the computers don't already have it, the runtime will be included with the install eventually. Our company does primarily embedded software and test software for host computers to test that embedded software. So we don't have mass produced PC software....so that's never been an issue for us. We sell the entire test sets, computer and all....so if we develop something in .Net, then the software, framework and all will already be on the computer when it is sold to the customer as a "test set". This allows us to develop, as long as customer has not dictated something special, in whatever environment/language we want (although 90% is currently in C/C++ right now). We have just a few groups that are trying to get a little more cutting edge and trying to bring some new technologies into the arena.


                      There are only 10 types of people in this world....those that understand binary, and those that do not.

                      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