I had the following code:
Contract.Requires(somecondition, "some message"/*some comment*/);
and while debugging at some moment the condition wasn’t met, and it threw the exception with the usual text, plus the comment! 😛 So I got this exception:
ContractException was unhandled.
Precondition failed: somecondition. "some message"/*some comment*/
So my question is, is this a bug or what? The second parameter of the method is of type string, but it only accepts literals, so I know the entire method is a hack, but it shouldn’t accept that comment, right?
This is because the “Code Contracts rewriter” rewrites the statement to enable the user to see all the information in the resulting exception message (including the condition expression itself, and apparently comments too).
http://visualstudiomagazine.com/articles/2010/06/23/code-contracts.aspx