Search code examples
.netcode-contracts

Code Contracts and Compilation


Does too much usage of code contracts slows down the compilation process. Secondly code contracts are part of debug mode only what if i set code contracts and always compile the code in release mode, then will code contract work? i suppose it wont which means developer will be forced to work in debug mode and when you are creating a setup then make it in release mode. Am i right?


Solution

  • Assuming Code Contracts from MS Devlab,

    1. Compiling: The Contracts tools activate after your compile. There is a rewriter for the runtime checking, and that takes (a little) time as part of your build.
      The static verifier runs after that, but in the background. You don't have to wait for it, unless you want to see the messages immediately.

    2. Runtime behaviour. This is configurable in multiple steps, from fully Off (benchmark), Requires only / Requires+Ensures (release) to Full (analysis / debug).