Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7671973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:10:47+00:00 2026-05-31T16:10:47+00:00

My code gets the CA1303 warning from Microsoft.Globalization , "Do not pass literals as

  • 0

My code gets the CA1303 warning from Microsoft.Globalization, "Do not pass literals as localized parameters", but my code is not actually passing a literal:

private void MyForm_Load(object sender, EventArgs e)
{
    UpdateTitle();
}

private void UpdateTitle()
{
    Version version = Assembly.GetExecutingAssembly().GetName().Version;
    CultureInfo culture = CultureInfo.CurrentUICulture;
    this.Text = String.Format(culture, "{0} v{1}.{2} Alpha r{3}", this.Text, version.Major, version.Minor, version.Build);
}

This code sets the title of the form to something like this, every time it is loaded:

MyFormNameAsSetInTheDesigner v0.1 Alpha r123

(version.build actually contains the SVN revision, which is auto-updated at each commit, I do not use revision because my versioning scheme uses only 3 numbers, major.minor.revision)

But this triggers the aforementioned warning, because it thinks I’m setting the titlebar text from a string literal. In fact, I’ve set Localizable = True in the designer, so that the string is fetched from a resource table.

I do not want to set the form’s title statically because (especially in the alpha and beta stages) I want it to have dynamic version numbers.

The question is what do I do so I don’t get a warning (for example, which code will do what I’m doing but be considered correct per FxCop, or how can I supress it for that line).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:10:48+00:00Added an answer on May 31, 2026 at 4:10 pm

    Based on the documentation for CA1303, the reason for the warning being raised is that you pass a literal string as the second parameter of the String.Format method, and in addition the second formal parameter of that particular overload is annotated with LocalizableAttribute.

    Therefore what the warning wants you to do is to put the string "{0} v{1}.{2} Alpha r{3}" as a localized resource in your resource assembly, and refer to it as such. Which is probably a good idea, as technically the structure of the format string and the fixed parts of its contents are localizable resources.

    If you simply want to make FxCop shut up, you can annotate UpdateTitle accordingly:

    [SuppressMessage("Microsoft.Globalization",
                     "CA1303:DoNotPassLiteralsAsLocalizedParameters" )]
    private void UpdateTitle() { /* ... */ }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This following code gets this compile error: " invalid types 'int[int]' for array subscript
My code gets an error saying: 'Eagle_Eye_Class_Finder.GetSchedule' does not contain a definition for 'GetDataFromNumber'
I use this code, but javascript is not loading. var head = document.getElementsByTagName('head')[0]; var
The below code gets me the users in the group but it is returned
The following WPF code gets the error: The name 'zipButtonOut' does not exist in
I thought .Net code gets compiled into MSIL, so I always wondered how do
The following code gets a 'report line' as an array and uses fputcsv to
The following code gets a JSON object and then spits its contents out into
I am developing on Eclipse on Windows and Code gets deployed on Unix. I
If you are familiar with TopCoder you know that your source-code gets a final

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.