Search code examples
c#visual-studiodesigner

Visual studio shows endless messages "Code generation for property 'valueMember' failed."


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.


Solution

  • 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.