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

StackOverflow https://stackoverflow.com/questions/23450183

  •  14-07-2023
  •  | 
  •  

Question

I get the following error when running Microsoft Code Contracts:

CodeContracts: Diagnostic: Failed to connect to any cache.

Was it helpful?

Solution

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).

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top