Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Code Contracts: Error "CodeContracts: Diagnostic: Failed to connect to any cache."

I get the following error when running Microsoft Code Contracts:

CodeContracts: Diagnostic: Failed to connect to any cache.

like image 946
Contango Avatar asked May 03 '14 21:05

Contango


2 Answers

The user manual for Code Contracts states:

Cache results: Controls if the analysis results are cached. If checked, the analysis tries to avoid analyzing methods whose outcomes cannot possibly change (because no contracts, no code, and no relevant metdata has changed). Enabling this option allows for faster turn-around times if using the static checker repeatedly. To share the cache among multiple developers, use a SQL server and put the server name in the SQL Server conguration box in the UI. Note: the SQL server connection uses Windows authentication to log onto the server. Your developers will need the right to create and modify databases.

Find out the correct name of SQL server installed on your machine (note that "localhost" will not work; it has to be the actual machine name):

enter image description here

Right click on the project, select "Properties", go to the "Code Contracts" tab (down the bottom of the list), then, add your machine name:

enter image description here

This works for Release 1.5.60911.10 (Sep 11, 2013). Perhaps future versions of Code Contracts will attempt to connect to "localhost" and/or accept "localhost" in this box, and/or automatically detect SQL Server 2012.

In my particular case, I didn't have "(localdb)\V11.0" installed; if I had installed this then it would have worked out of the box (it must be defaulting to this internally).

like image 106
Contango Avatar answered Oct 15 '22 15:10

Contango


Just uncheck the "Cache Results" option under the "Static Analysis" section of "Code Contracts" property page.

like image 22
ahmkara Avatar answered Oct 15 '22 14:10

ahmkara