Erroneous "Non-existing argument in format string"

I have the following piece of code:

int hr = comExc.ErrorCode;
String Message = String.Format("There was an error.\nHRESULT = \n", hr.ToString(), comExc.Message); And ReSharper 2.0.236.68 insists that is invalid whilst highlighting "hr.ToString()" as not used within the format string. I guess the parsing of format strings is not quite there yet in this beta version :)

AL

4 comments
Comment actions Permalink

Hello Alfonso,

I'm not sure about this particular problem, but it seems you're using a very
outdated build. Please try to
upgrade to the latest one (241).

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

I have the following piece of code:

int hr = comExc.ErrorCode;
String Message = String.Format("There was an error.\nHRESULT =
\n", hr.ToString(), comExc.Message); > And ReSharper 2.0.236.68 insists that is invalid whilst
highlighting "hr.ToString()" as not used within the format string. I
guess the parsing of format strings is not quite there yet in this
beta version :)

AL



0
Comment actions Permalink

Alfonso,

R#'s correct, for arguments are numbered staring with 0. So hr.ToString() is
not used, and is bound to nothing.

--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

Hello Alfonso,

The error report is correct... The placeholders for string.Format are zero-based
and your code should be:

String Message = String.Format("There was an error.\nHRESULT = \n", hr.ToString(), comExc.Message); Greetings, Guy > I have the following piece of code: > > int hr = comExc.ErrorCode; > String Message = String.Format("There was an error.\nHRESULT = > \n", hr.ToString(), comExc.Message); > And ReSharper 2.0.236.68 insists that is invalid whilst

highlighting "hr.ToString()" as not used within the format string. I
guess the parsing of format strings is not quite there yet in this
beta version :)

AL



0
Comment actions Permalink

My apologies, you're all absolutely correct. I inherited this piece of code yesterday and I obviously didn't look at it long enough to click :)

So there you have it, R# doing its job well! As I always say, it's not the software, it's the user who makes the mistakes (most times anyway ;)

Thanks again for waking me up. I obviosuly didn't have enough coffee yesterday :)

AL

0

Please sign in to leave a comment.