问题
I get the following error when running Microsoft Code Contracts:
CodeContracts: Diagnostic: Failed to connect to any cache.
回答1:
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):
Right click on the project, select "Properties", go to the "Code Contracts" tab (down the bottom of the list), then, add your machine name:
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).
回答2:
Just uncheck the "Cache Results" option under the "Static Analysis" section of "Code Contracts" property page.
来源:https://stackoverflow.com/questions/23450183/microsoft-code-contracts-error-codecontracts-diagnostic-failed-to-connect-to