BUG: The Resx file is not updated when you remove a control (316643)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual J# .NET (2002)
  • Microsoft Visual J# .NET (2003)
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • 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.

MORE INFORMATION

Steps to Reproduce the Behavior

NOTE: Building an application that has specific localized resources does not always flush changes.
  1. 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.
  2. 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.
  3. Click Button in the Toolbox, and then draw a button (Button1) on Form1.
  4. Change the Localizable property for Form1 to True.
  5. Type the following string for the Text property of Button1:

    Default String

  6. Change the Language property for Form1 to German.
  7. Type the following string for the Text property of Button1:

    German String

  8. Change the size of Button1 to force a code generation into the resource files.
  9. Delete Button1.
  10. 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).
  11. 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.
  12. Type the following string for the Text property of Button1:

    My New String

  13. Run the solution and notice that "My New String" is overwritten with "Default String", which is the previous string.

Modification Type:MajorLast Reviewed:1/20/2006
Keywords:kbvs2005applies kbvs2005swept kbvs2002sp1sweep kbbug kbLocalization kbpending KB316643