Failed to load toolbox item. It will be removed fr

2020-05-30 09:32发布

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.

10条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-05-30 10:02

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.

查看更多
Juvenile、少年°
3楼-- · 2020-05-30 10:02

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.

查看更多
Luminary・发光体
4楼-- · 2020-05-30 10:05

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.

查看更多
劳资没心,怎么记你
5楼-- · 2020-05-30 10:06

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.

查看更多
登录 后发表回答