0

I was making a winforms user control. After creating and building, I looked at the toolbox and there was a user control I made. But when I tried to drag and drop it from the toolbox it told me." Failed to Load tool box item XXX (user control name).It will be removed from the toolbox.".But the control in the project is fine and there are no errors. It doesn't change even if I delete it a few times and re-enter it. What should I do? Build environment: x64

MJ Nine
  • 11
  • 3
  • Does this answer your question? [How to put a UserControl into Visual Studio toolBox](https://stackoverflow.com/questions/3446429/how-to-put-a-usercontrol-into-visual-studio-toolbox) – Vivek Nuna Feb 27 '21 at 07:47
  • I've already turned on that option. – MJ Nine Feb 27 '21 at 07:50
  • 2
    Set the target to AnyCPU. If you have built a Project for your UserControl, make sure all Projects in your Solution target AnyCPU. -- This doesn't mean that the UserControl will work if it has other problems. See that it has an empty Constructor, possibly post the code that initializes the UC and any other component in it (what's in the Designer should be safe, unless you tampered with it). – Jimi Feb 27 '21 at 09:11
  • Most likely the designer has an issue with it and you should look into that. Often it is code in a `Paint` event that can't run because of some runtime dependency. You can use the `if (DesignMode)..` check to skip such code.. Then recompile and it will re-appear.. – TaW Feb 27 '21 at 09:12
  • @Jimi I can't modify the build environment of another project in the same solution (SQLite.x64 library compatibility issue). However, you can use user controls to modify your project's build environment. Do I just need to change the build environment of this project? – MJ Nine Feb 27 '21 at 09:18
  • If the UC is part of the Solution (not an external library), set the Target CPU to AnyCPU in the UC alone. It works anyway. You could have some problems when you rebuild the Solution: a Form that contains your UC may show the usual *cannot find Component X, is either undeclared or was never assigned*. Cleaning and rebuilding also usually solves it. Otherwise, clean and rebuild, close the Form's files, exit the IDE and start it back. – Jimi Feb 27 '21 at 09:27

0 Answers0