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

  • SEARCH
  • Home
  • 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 7808727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:12:57+00:00 2026-06-02T03:12:57+00:00

In cases where the full text of the format string is static and known

  • 0

In cases where the full text of the format string is static and known at compile time, shouldn’t a missing format string parameter be a compile-time error or, at the very least, warning?

ReSharper catches this, but it’s just an underlined squiggle. I was under the impression that this would trigger a general compile-time error:

string x = string.Format("soeuotnh {0}");

Is there any way to trigger a warning on this kind of error without having to run my code through FxCop or something? Even C/C++ compilers will trigger an warning/error for such a blatantly clear bug (though they generally won’t check type-safety).

  • 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-06-02T03:12:59+00:00Added an answer on June 2, 2026 at 3:12 am

    I have filed a request for consideration of this feature on Microsoft Connect, as I feel that

    • The answers saying “people would prefer their code compile and fail at runtime if it’s a not very hot codepath” is just absurd and has no place in non-interpreted languages, and especially not explicitly-defined, strongly-typed languages that place such an importance on type safety as C#.
    • The answers saying the compiler is physically not capable of (ever) deducing the format string and the parameters array at compile time are also incorrect. Yes, there are times when the compiler cannot deduce one or the other (or both) at compile time, and there’s nothing that can be done about those, but many other times, it has the full info at its disposal.
    • The answers saying this is outright not the compiler’s job just because the spec doesn’t mention throwing a warning for this kind of behavior are missing the fact that the spec is the minimum that a compiler should implement, and the compiler is free (and does indeed to a great, great extent) to go above and beyond so long as it’s not in conflict with the spec.
    • The answers saying C compilers don’t do this either are plain wrong – I have posted examples otherwise.
    • The answers saying the code sample I posted does not throw an exception at runtime are blatantly wrong (though most have been edited since then).

    At the end of the day, it’s a “yes it could, no it doesn’t, maybe it should” situation. I was trying to make sure that there wasn’t something I could set in the compiler (not third party software) to make it more agressive with its warnings or if there were some way I could change my code to make it throw an exception (for instance, declaring everything as const), but it turns out (thus far) that that is not possible. Regardless of the response of the Visual Studio team on the issue I opened on MS Connect, the fact remains that the compiler certainly can catch a great many string formatting exceptions at compile time, that it would be a benefit… but it remains for the VS team to determine whether or not it is something worth implementing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I pass const string strEditParams = TaskID={0}&TaskName={1}; string strEditValues = string.Format(strEditParams, lbl.Text ,
I am trying to do a full text match on a string. Something like
I have some test cases. The test cases rely on data which takes time
In the majority of cases I see Log instances declared as follows: public static
On certain error cases ATL invokes AtlThrow() which is implemented as ATL::AtlThrowImpl() which in
I'm trying to work out some of the finer details of the Full-Text Search
I would like to be able to use Full text search in Code First
I have a full screen activity with a ExitText. When edit text is clicked(gets
I am reading a very large file and extracting some small portions of text
I need to allow full-text searching on two fields that are concatenated together. In

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.