I've got a WinForms project that I've had for quite some time, and now suddenly, I can't open the designer anymore and when I try to open the designer I get an error that says
could not find type 'System.Collections.Generic.List'
All of the code builds ju开发者_StackOverflow中文版st fine, but I can't use the designer anymore, and I don't know what happened, nor do I have any idea where to look to solve the problem. Has anyone ever run into this or have any insight?
Just in case anyone is curious, here's what happened.
Somehow, via accident a line of code got added into the Forms InitializeComponent Method that was basically just constructing a generic list. Simple code, no big deal, and it compiled just fine.
Well it seems that you can't put anything with Generics in the InitializeComponent method. I'm not sure why you'd ever need to do it, but if you're seeing this error, make sure you don't have any generic code in InitializeComponent.
Unload and re-load you project. Rebuild and open your form in Designer view. If your code is compilable, this should do the trick.
Have you maybe changed the .NET version of the project?
Also, try removing and regenerating the designer file.
Try to clean your solution and build again. Hope it helps.
All prior answers did not work for me. Here is how I fixed the issue:
1) Remove all custom code from the .designer.cs file.
2) Make sure a default constructor is implemented - adding arguments to the constructor breaks the designer view since for that one the default constructor is attempted to be called.
So with the System.Collections.Generic reference in the form.cs file and not the form.designer.cs file and with default constructors present it started to work fine - no solution reload needed.
精彩评论