Microsoft KB Archive/943455

= Opening a C++ Form in the designer may not deserialize some properties of components or controls from the code =

Article ID: 943455

Article Last Modified on 10/6/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Express Edition
 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Team Edition for Software Architects
 * Microsoft Visual Studio 2005 Team Edition for Software Developers
 * Microsoft Visual Studio 2005 Team Edition for Software Testers
 * Microsoft Visual Studio 2005 Team Suite
 * Microsoft Visual Studio 2005 Service Pack 1

-



Source: Microsoft Support



RAPID PUBLISHING
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.



Action
On a C++ Form, there is a component or control that hides a member of its base class with a property. The component or control is selected and the property is set using the property grid. The form is saved and closed. When the form is reopened and the component or control is selected, the property value that is specified in the code will not be displayed in property grid.



Result


Cause
Microsoft has confirmed that this is a |bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Resolution
In the control library, change the name of one of the members so that the derived class's member no longer hides the base class's member.

-or-

Set the property in code, after InitializeComponents, though editing the property via the Property Grid will no longer have an effect.



MoreInformation
Steps to reproduce

1. Start Visual Studio .NET 2005

2. Create a new Visual C++ Windows Forms Application

3. Add a new Visual C# Class Library project to the Solution.

4. Add a new Component to the C# Class Library, call it baseComponent.

5. Open baseComponent.cs in the code editor and add the following Method the baseComponent class.

public void MyMember

{

}

6. Add a new Component to the C# Class Library, call it derivedComponent.

7. Open derivedComponent.cs in the code editor and add the following Property to the derivedComponent class.

private int myMember;

// intentionally hiding the base class member, use the 'new' keyword to so we don't get warning CS0108.

public new int MyMember

{

get { return myMember; }

set { myMember = value; }

}

8. Open Form1.h in the designer and add a derivedComponent to it.

9. Select the derivedComponent and using the Property Grid, set the value of MyMember to 3.

10. Save, close, and reopen Form1.h.

11. Select the derivedComponent and see the value of MyMember is not set to 3 in the Property Grid.

In addition, if the Form is modified and saved, the default value of the property will be persisted to the file.

Note, the language of the class library is irrelevant to the problem, but the Form must be a C++ Form.



DISCLAIMER
MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.

Keywords: kbnomt kbrapidpub KB943455

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.