Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Fixing CA1303 - DoNotPassLiteralsAsLocalizedParameters

Back to Forum: Tech Off
  • User profile image

    Is there some way to fix the DoNotPassLiteralsAsLocalizedParameters problem, without just suppressing it?

    I want it to load the strings from a resource file, and have got that working.
    The problem is, that I want to have the strings from the default locale shown on the controls in the controller, so I don't have empty labels, buttons etc.

    Can I do that?

    I'm using C# 2.0

  • User profile image

    Come on, nobody who knows how to fix this?

  • User profile image

    So it has only been 9 months since you posted this!  I can tell you how I fixed it in my code and you probably have figured this out by now:

    using System.Resources;

    readonly ResourceManager resourceManager = new ResourceManager("{namespace that is setup in project properties}.Resources", Assembly.GetExecutingAssembly());

    Under the InitializeComponent() method I changed out the existing this.Text = "My Form Name"; with:

    this.Text = resourceManager.GetString("theTextNameThatIPutInResources.resx", CultureInfo.CurrentUICulture);

    So what you want to do is make sure that in Resources.resx you create a new item under Strings that you will refer to in the above line of code.

    All of this code should be placed in your frmName.Designer.cs partial class file.

    Hope this helps anyone else who had to deal with this utilizing Code Analysis.

  • User profile image

    leitej wrote:
    All of this code should be placed in your frmName.Designer.cs partial class file.
    Is it really a good idea to recommend that people modify a code-generated file?

  • User profile image
    Sven Groot

    All you need to do is set the Localizable property of the form to true in the designer. Then all the localizable properties of the form and its controls will be stored in the resource files associated with the form. This will get rid of that FxCop message.

    Then just change the Language property and then change all the strings etc. if you want to localize the form. Easy as strawberry pie.

    That way you also don't have to write resource-loading code for the form, it's all automatic, and fully designer-supported.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.