Failed to load toolbox item. It will be removed from the toolbox
Asked Answered
C

13

37

I have a WinForm application. I also have created my own User Control for it. Everything worked fine. Until today that I received the error message when I try to add it back to my program (I never removed it. Visual Studio did).

Failed to load toolbox item #UserControlName. It will be removed from the toolbox.

I have it in my solution explorer but it vanishes from my toolbox after this error. I also receive the warning that says:

'#UserControlName' is never assigned to, and will always have its default value null.

And when I look at my designer code, that is true. But I haven't done anything with my designer code. My user control is defined there but not instantiated. How can I put it back?

Does it have anything to do with the fact that I changed my build platform from x32 to x64? If that is the case I will be surprised because the program was working fine after that change.

Corniculate answered 4/12, 2014 at 8:29 Comment(0)
I
0

At times like these, you'll be forced to tinker with the designer code. As long as you don't make drastic changes in the designer code, you shouldn't break anything. To play it safe, re-instantiate the object where the other controls are instantiated (near the top of the page). The designer should fill in the blanks for properties and such.

This should also return the control to the toolbox.

Immemorial answered 5/12, 2014 at 6:42 Comment(4)
Yes, I think I did the same. It's a recurring thing. I don't touch anything and then VS just keeps forgetting things. So I clean those user controls and drag them again and it works...for a while.Corniculate
I had a similar issue and i believe the fix is to trick visual studio into believing that the .Designer file has not been manually edited. to simulate this you need to make sure that the order of declaring and instantiating controls is the same in the .Designer file. This is what fixed it for me.Defensible
This answer is unclear. Just what does one do with the designer code? I assume by that you mean the source file named like MyWonderfulControl.designer.cs.Lepley
This might be a way around the visual editor, but is not a solution to the problem! I downvoted because there are some real solutions for various cases and this should not be the accepted answer.Hennebery
P
55

I was suffering from the same issue for one of our applications and could not find a solution. So I created the user and custom controls manually. After searching the web again I finally found why the designer is failing for this particular project. The answer is that project is 64 bit and Visual Studio is still does not have a 64 bit version, it is still 32 bit. So the designer could not load the controls in 64 bit applications or in class libraries. Read Microsoft's article about this. There was an article on Visual Studio web site but it was removed. See the the answer in Visual Studio support forum.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/77e10b58-43cc-4aab-919f-888f14f99571/x64-class-library-of-user-controls?forum=csharpgeneral

Partida answered 19/6, 2017 at 10:22 Comment(6)
that was the problem in my case as well. I had to set the project to 32bit so it would allow loading the user controls. Thanks for the tip.Imaginable
solved the problem for me as well - this should be the accepted answerBrynnbrynna
This link is now dead and unfortunately there is no archive available.Homochromous
Holy crap! I had to switch the compile to 64 bit for another aspect of my project and never considered that the designer might require 32. Thank you so much!Jonquil
Great answer to a very poorly worded error. Note that after VS removes the control from the toolbox (where it was in alphabetical order), it may shove it to the bottom of the list when you change your Target CPU from 64 to Any Cpu. Nothing is ever easy.Scholasticism
Same here. Couldn't figure out why a User Control I made a while back suddenly wasn't working on the form I'd added it to. I had to switch the app to 64-bit recently to solve a problem. Of course, now I have to run Debug in 32-bit which means I'll still have the same problem that 64-bit solved when debugging.Lading
R
45

I had the same issue lately. As this (nor any other answer on this site and on the internet) actually helped me, I found out the way to fix it.
Just clean the files and rebuild the solution. As simple as that.

Repartee answered 21/8, 2015 at 20:51 Comment(3)
I was having this same issue and ^this (cleaning/rebuilding) worked for me. Editing the designer didn't work and closing/reopening VS didn't work. I was placing a user control inside another user control.Host
I cleaned all projects, rebuilt, and still have the same problem as Disasterkid. Even quit VS and restarted it between cleaning and building. Great that this worked for someone, but I guess I'll have to prepend 'disaster' to my user name too.Lepley
I just had a similar issue in VS 2017, and the clean/rebuild worked for me.Whereby
L
9

I was having same issue but I find the solution:
Click on "Project_Name" with left mouse and click "Build" then you can add the UserControl to your WinForm.

Lepidosiren answered 16/12, 2019 at 12:36 Comment(0)
D
5

Change to AnyCPU and rebuild the project. Visual Studio has problems with controls being 64bit.

Dawnedawson answered 27/8, 2018 at 8:34 Comment(2)
Has this ever been fixed? All of my projects are 64 bit !!Acescent
Still a problem in Vs2019. Since I use a library that explicitly does not compile with anycpu, user controls are not an option.Insulation
R
3

You don't have to necessarily insert the user-control manually. I had the same situation an there was a reason for it.
In my case, it failed because the EXE assembly was compiled to 'mixed-mode' by using CLR support type /clr. After changing it to 'managed-only' by setting type /clr:pure, it worked.
For details, see my answer here at SO.

Rooftree answered 1/3, 2017 at 10:32 Comment(0)
D
3

Right click - Rebuild Solution fixed it for me!

Dextran answered 31/3, 2021 at 8:58 Comment(1)
Worked but now I have the problem that right-clicking on the user control does not show control propertiesTrachyte
A
2

After many hours of head scratching with this problem with a large custom control with few changes from a previous working copy in source control I copied all the code into a new control name and file and it all worked.

This was to identify the problem line(s) of code since the debugger would not co-operate. The copied control (along with heaps of support code and modules) worked okay.

So these are the very simple steps that fixed my original code

  1. In solution explorer rename the file (I just added an s at the end)
  2. Rebuild
  3. Test the control can now be added to a plain form
  4. Rename the control back to its original name

Step 4 might be optional for you but if you have source control and it's a in a library you would want to do this.

This brought the control back onto all my forms that weren't working (so far as I can tell). It seems the problem is in VS that somehow remembers it doesn't like it?

Hope this helps and I hope I find this message next time I get this when I have forgotten the fix :)

P.S. Clean, rebuild and/or re-run the solution is the old stand by for this problem but this time it was just one custom control in a whole (DLL) class of them. Hope this helps.

Antidisestablishmentarianism answered 9/12, 2017 at 22:54 Comment(1)
I did this as well, but I had an additional step - I had to comment out any references to that control in my code, then rebuild, then restore the commented-out references.Freesia
H
2

For me, after adding the userControl, I rebuild the application first then refreshed the items on the tool box by going to projects => Refresh project toolbox items

Hogwash answered 27/2, 2019 at 7:34 Comment(0)
J
2

Mostly caused by 32 bit / 64 bit architecture. Before Visual Studio 2022 the VS built in 32 bit, therefore cannot show 64 bit components.

Solution 1:

  • Create a new solution configuration in Configuration Manager with name: "Debug_FormDesign" or anything else.
  • Set the Configuration to the above name for all projects and set the platform to "AnyCPU".
  • Now open all projects Compile settings step by step, select the above configuration and change the Compile -> Target CPU option to AnyCPU.
  • Close all opened windows.
  • Clean solution.
  • Restart VS.
  • Select the "Debug_FormDesign" configuration in toolbar as active.
  • Rebuild solution.
  • Open the form designer -> Should work now.

You can easily switch back to the default "Debug" configuration after finish with the GUI.

Solution 2:

  • Use Visual Studio 2022.
Jyoti answered 19/8, 2021 at 12:14 Comment(1)
Still happening to me in VS 2022Coffeng
I
0

At times like these, you'll be forced to tinker with the designer code. As long as you don't make drastic changes in the designer code, you shouldn't break anything. To play it safe, re-instantiate the object where the other controls are instantiated (near the top of the page). The designer should fill in the blanks for properties and such.

This should also return the control to the toolbox.

Immemorial answered 5/12, 2014 at 6:42 Comment(4)
Yes, I think I did the same. It's a recurring thing. I don't touch anything and then VS just keeps forgetting things. So I clean those user controls and drag them again and it works...for a while.Corniculate
I had a similar issue and i believe the fix is to trick visual studio into believing that the .Designer file has not been manually edited. to simulate this you need to make sure that the order of declaring and instantiating controls is the same in the .Designer file. This is what fixed it for me.Defensible
This answer is unclear. Just what does one do with the designer code? I assume by that you mean the source file named like MyWonderfulControl.designer.cs.Lepley
This might be a way around the visual editor, but is not a solution to the problem! I downvoted because there are some real solutions for various cases and this should not be the accepted answer.Hennebery
D
0

Check in your form.designer file if there is a left-behind property with that type. It happened to me several times. After I removed that line and rebuilt the project, everything started working.

Dawnedawson answered 1/9, 2018 at 23:7 Comment(0)
H
0

In my case it helped to manually include the header files of the created user controls at the top of the Form where these controls are to be used.

Hennebery answered 8/6, 2019 at 18:22 Comment(0)
S
0

I got this error with an SDK project file. It seems I had forgotten to add the OutputType to the project. Without the OutputType set to WinExe, I was able to use the designer and build/run etc. but this error showed up when I tried to add the control to a form in the same project.

The following line should be in an SDK project file:

    <OutputType>WinExe</OutputType>
Sarracenia answered 16/5, 2023 at 1:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.