Code Contracts
Discuss and provide feedback on Code Contracts.
Announcements
Welcome to Code Contracts for .NET
Mike BarnettMicrosoft EmployeeFriday, February 20, 2009 2:28 AMWe are so happy that you are interested in Code Contracts! You are at exactly the right place for learning how to use contracts from any .NET language to:
- Specify method preconditions for expressing conditions that a caller must meet in order to call a method.
- Specify method postconditions for expressing conditions that the implementation of a method must meet before returning. Conditions can be specified for both normal termination as well as exceptional termination.
- Specify object invariants that describe the healthy states for an instance of a class.
We currently provide three tools for making use of contracts:
- A binary rewriter that operates as a post-build step to inject the contracts into the appropriate places for them to be evaluated at runtime.
- A static checker that operates as a post-build step to analyze your code without even executing it for potential contract violations.
- A documentation generator that adds information about the contracts to the XML documentation files for your project.
The installer for these tools is available for either commercial or non-commercial use.
We welcome you to use the forum to ask questions about how to use contracts and the tools, to make suggestions for how we can improve, and --- if you really must --- to report bugs and problems.
You can also check out our home page at Microsoft Research.External projects using Code Contracts?
Mike BarnettMicrosoft EmployeeThursday, March 22, 2012 5:09 PMWe have added a section to our web site listing the external projects that we know about which are using Code Contracts. If you would like your project listed, please send us a link and we'll add it to the list. This would really help us in our efforts to get the project more fully supported by the product groups.
Thanks!
Mike
New Release for Visual Studio Editor Extensions for C# (v1.4.40602.0)
Mike BarnettMicrosoft EmployeeSaturday, June 04, 2011 12:14 AMThere is a new release of the VS 2010 editor extensions on the VS Gallery. The extensions themselves haven't changed, but the underlying infrastructure has had many contract-related improvements so I hope it performs better. I will try to get around to fixing the performance problems that everyone has been noticing.
If you haven't tried it yet, then please do and let us know what you think!
To review, the extensions should show you method contracts in the following situations:
- While you are typing a call to a method: the signature helper window should show you each overload's contract in the same window as the signature and exception information.
- Hovering over an existing method call: the quick info window should show you the method's contract in addition to its summary information.
- Method override and interface implementation definitions: a small graphic should pop up above the method definition showing any inherited contracts.
- Metadata windows: if you "go to definition" for a type/method that is defined in an external assembly then the metadata window that VS creates should be augmented with method contracts.
Documentation is available at the MSR Code Contracts site.
Release 1.4.50327.0 is now live! (Includes Dev11 support -- see note below)
Mike BarnettMicrosoft EmployeeThursday, March 29, 2012 1:28 AMA new release of Code Contracts is now live. Besides some small bug fixes, this release provides support for Dev11. NOTE: In order to see the Code Contracts pane in Dev 11, you must manually run "devenv /setup" from a command prompt (either a Visual Studio command prompt or else one that has a path set so "devenv.exe" (for Dev11) is found).
If the download links have the usual caching problem, then you can try these:
Download CodeContracts
Please keep using the forum for communicating with us. We are trying to make the case for Code Contracts to be included in Visual Studio as an official product. Please send us your feedback as soon as possible, especially if you have any details about how exactly it has helped your development process.
Dev11 support
Mike BarnettMicrosoft EmployeeThursday, March 01, 2012 5:44 PMIn order to see the Code Contracts pane in Dev11, you must run "devenv /setup" from a command prompt after installing the tools.
If you have any problems, please let us know!
Filtering and SortingUse these options to narrow down the question and discussion list.
- 07

"Call-site Requires Checking" does not work on constructors.
Gilles TOURREAUMVP1 hour 26 minutes ago - 072

Debugger gets confused when using Contract.Requires and a lambda capturing a variable
Virtlink Sunday, May 20, 2012 1:47 PM - 078

Incorrect "Suggest Ensures" scenario with array bounds
Viacheslav Ivanov Saturday, May 19, 2012 10:18 PM - 054

Failing contract with simple arithmatic
Alan Bradbury Saturday, May 19, 2012 10:05 PM - 64590

Possibly unboxing a null reference - Nullables
Dave Sexton Monday, March 15, 2010 3:00 AM - 11615965

Missing Contracts on Libraries
Manuel FahndrichMicrosoft EmployeeTuesday, March 10, 2009 6:20 AM - 1374

Problem with naming my own project *.Contracts.dll
Rolf de Vries Thursday, May 10, 2012 9:28 PM - 63621

Cannot extract contracts from rewritten assembly
sterioma Tuesday, December 29, 2009 12:17 PM - 5801

Code Contacts June 2011 -> Mazrch 2012 SLOWER
Zubin Appoo Thursday, April 19, 2012 6:12 AM - 62258

[bug] Invalid contract for Buffer.BlockCopy
Ilya Margolin Thursday, August 18, 2011 8:38 AM - 1281

Static checker uncaught exception
p.roman Monday, May 07, 2012 12:14 PM - 0459

Need VS 11 (Beta) Editor Extensions or VS 2012
Frank Dzaebel Thursday, May 03, 2012 9:02 AM - 0349

Custom Contract Assembly No Longer Working
Dave Sexton Wednesday, May 02, 2012 3:47 PM - 0327

windows8 beta installation problem
Asoke Bhattacharyya Wednesday, May 02, 2012 2:29 PM - 82443

What is the future of code contracts?
wilhelm.medetz Wednesday, September 21, 2011 2:29 PM - 3330

Do codeContract only throw exceptions?
devBrix Wednesday, May 02, 2012 5:54 AM - 5449

Can extra options be specified via an environment variable?
gallóglaigh Monday, April 23, 2012 7:15 PM - 81051

Code Contracts and VS 11 Beta - 'StanPackage' did not load correctly error
wilhelm.medetz Friday, March 30, 2012 7:10 AM - 2601

Bug report: ccdocgen crash
Stephen Cleary Tuesday, April 10, 2012 2:23 PM - 42411

Unhandled Exception [v1.4.40602.0]
Andrey Titov Tuesday, July 19, 2011 4:04 PM

