0

I have a snippet of code using code contracts that I expect to fail at compile time

...
int myInt = -1;
Contract.Ensures(myInt > 0);
...

The line using the contract is grayed out and I get a tool tip saying, "Method invocation is skipped. Compiler will not generate method invocation because the method is conditional, or it is partial method without implementation."

Here is a screenshot of the code contract from that project's properties: http://screencast.com/t/Q0famE8TR2

I am using .net 4.5.

Teeknow
  • 1,015
  • 2
  • 17
  • 39

1 Answers1

1

That message is coming from ReSharper, which I assume you're using even though you didn't mention it. ReSharper doesn't understand how Code Contracts works.

Specifically, it doesn't know that the Contracts page settings will cause CONTRACTS_FULL to be defined automatically. If you want to get rid of those warnings, you need to explicitly add CONTRACTS_FULL to your list of conditional defines on the normal Build properties page of your project.

Michael Edenfield
  • 28,070
  • 4
  • 86
  • 117
  • I'm using VS2013 + R#10. Adding 'CONTRACTS_FULL' to the 'Conditional compilation symbols' field within the Build Properties of my project fixed the grayed out line for me. – JTech Dec 16 '15 at 05:42