Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contract.Assert do not throw compilation error

I am trying to add validation for my type at compilation time using Contract but unfortunately it do not work. For example code below do not give compiler error while compiling project. Should I enable something?

Contract.Assert(false, "Invalid state!");
like image 210
Tomas Avatar asked Jun 19 '12 11:06

Tomas


1 Answers

Yes, you need to enable the static checking. Go into the project properties and visit the "Code Contracts" tab. Of course you'll need to have installed the static checker extension first, which IIRC is only available for Visual Studio Ultimate. See the user documentation for details of the exact options available.

Note that this happens after the initial compilation phase, so sometimes you'll see a delay between the first part of the build and the results of the static checker. (It's not really a "compiler" error - it's a "contract checking" error.)

like image 67
Jon Skeet Avatar answered Sep 21 '22 00:09

Jon Skeet