Microsoft KB Archive/316643

= BUG: The Resx file is not updated when you remove a control =

Article ID: 316643

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual J# .NET 2003 Standard Edition
 * Microsoft Visual J# .NET 2003 Standard Edition
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Basic 2005 Express Edition

-



This article was previously published under Q316643



SYMPTOMS
If you add a control to a form and then localize it, some strings may persist when you delete and replace the control with a control of the same name. You may see strings that are intended for the deleted version of the control that are overwriting the text property value that is entered in the design environment when the solution is run.



CAUSE
When you localize a control, strings are placed in the Form1.resx file or other localized .resx files. When the control is removed, these strings remain in .resx files. If you place a control with the same name back on the form, these strings are still referenced to the control by way of the control name. At runtime, these strings are retrieved from the .resx files and they overwrite any strings that were entered in the design environment. If the added control has a different name, the residual strings are not a problem.



RESOLUTION
If you delete a control that you have localized and you want to add a new control, make sure to give the new control a different name. If you first create a control called Button1, you localize it, and then you delete it, you need to add a control with a different name, such as Button1A. You can also try returning the Language property of the form to (Default) before you delete the control.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
NOTE: Building an application that has specific localized resources does not always flush changes.  If the Visual Studio .NET or Visual Studio 2005 integrated development environment (IDE) is running, on the Files menu, click New, and then click Projects. If you are starting the IDE, click New Project on the Start Page. In the New Project dialog box, under Project Types, click either Visual Basic Projects or Visual C# Projects, and then under Templates, click Windows Application. In the Name box, type WindowsApp1, and then click OK.

Note In Visual Studio 2005, click either Visual Basic or Visual C# under Project Types. Click Button in the Toolbox, and then draw a button (Button1) on Form1. Change the Localizable property for Form1 to True. Type the following string for the Text property of Button1:

Default String

</li> Change the Language property for Form1 to German.</li> Type the following string for the Text property of Button1:

German String

</li> Change the size of Button1 to force a code generation into the resource files.</li> Delete Button1.</li> Build and run the solution.

If you look at the localized resource files, Form1.resx and Form1.de.resx, you notice that they contain references to Button1 including the previously entered Text values. To see the contents of these files, double-click a file in Solution Explorer (click Show All Files to make these files visible).</li> Once again, click Button in the Toolbox, and then draw a button on Form1. Use the default button name, Button1. You may receive the following warning:

The language you are currently localizing to differs from the invariant language. Default values for the component you have just added have been saved into the invariant language resource file. Remember to change languages back to the invariant language and update any properties for this component.

Note In Visual Studio 2005, you receive the following warning message:

Components cannot be added in localization mode. Select (Default) in the Language property to return to the default form and add components.

If you receive this message, the IDE may be recognizing that the control is being added with a language other than the default language.

To reproduce the problem click OK to close the error message. To resolve the problem, set Language to (Default), delete the control, and then add it once again.</li> Type the following string for the Text property of Button1:

My New String

</li> Run the solution and notice that &quot;My New String&quot; is overwritten with &quot;Default String&quot;, which is the previous string.</li></ol>

Keywords: kbbug kblocalization kbpending kbvs2002sp1sweep kbvs2005applies kbvs2005swept KB316643

-

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

© Microsoft Corporation. All rights reserved.