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条回答
The star\"
2楼-- · 2020-05-30 09:46

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.

查看更多
地球回转人心会变
3楼-- · 2020-05-30 09:46

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.

查看更多
劫难
4楼-- · 2020-05-30 09:51

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

查看更多
迷人小祖宗
5楼-- · 2020-05-30 09:53

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.

查看更多
闹够了就滚
6楼-- · 2020-05-30 09:54

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

查看更多
够拽才男人
7楼-- · 2020-05-30 10:01

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

查看更多
登录 后发表回答