Visual studio shows endless messages “Code generat

2019-04-18 03:13发布

After several days of happily hacking away on this C# app using Visual Studio 2008, I get struck by a barrage of error dialogs showing:

Code generation for property 'valueMember' failed.
Error was: 'Object reference not set to an instance of an object.'

This happens now often when I make a tiny change in the designer, e.g. shift a control a few pixels, and then try to save. Several such error dialogs appear each second, keeping me busy cancelling all those by hammering the Enter key while trying to get alt-F4 to get VS to close.

Eventually I do get VS to close and to save the changes I made. After restarting VS, I do "clean" on the entire project, then "build" and everything works fine, the app runs fine, no problems.

Until I make another slight change in the form designer.

I don't know about any property valueMember in my app.

This makes me crazy, it is a real showstopper for my project. Any help is appreciated.

5条回答
【Aperson】
2楼-- · 2019-04-18 03:41

I had to face this problem. As I have not found the solution (much inheritance), I can tell: .SuspendLayout() and .ResumeLayout() may be missing in code or one of them. The same is with .BeginInit() and .EndInit(). It is expected between them, that there will be = new ... and some settings for properties. Maybe someone facing this problem would find the solution with this information.

查看更多
我想做一个坏孩纸
3楼-- · 2019-04-18 03:50

Try to Close and reopen the Visual Studio. maybe it seem silly, but it works!!

查看更多
ら.Afraid
4楼-- · 2019-04-18 03:52

Similiar to @Chanipoz's answer (close/re-open) my component-rich/user-controls-everywhere forms app started to compile happily after I closed down the main form designer window.

I've had this code stack for years and have never seen the error until today. Not sure where it's coming from. But, something today about having the form open in the designer made everything unhappy. Simply closing it off of the screen made it all go smooth.

查看更多
Viruses.
5楼-- · 2019-04-18 03:54

As this is happening at design time, it is likely that you have a custom control which requires a parameter or other value which does not have a default.

When in design view in Visual Studio; a control instance is created to render it on the visual editor, but if the control requires a property to be set before it can be rendered, it will result in an error.

Can you check that all custom controls have default values, and anything referenced in the constructor that cannot have a default is wrapped by DesignMode property - see http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode.aspx.

查看更多
时光不老,我们不散
6楼-- · 2019-04-18 04:07

You can debug the designer using another visual studio and attach to process. If you got exception it should be easy to find it that way. In general when openning the designer the constructor and of course initializeComponent is running.

查看更多
登录 后发表回答