Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading user information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Daryl Zuniga and Mike Barnett - Xml Documentation from Code Contracts for .Net

8 minutes, 30 seconds


Right click “Save as…”

Mike Barnett and Daryl Zuniga, a high school intern at RiSE, sit down to talk about Code Contracts for .NET and documentation. Daryl has been working this summer on a tool that inserts contracts elements into the Xml Documentation files generated by the C#/VB compiler. Daryl also updated the Sandcastle stylesheets so that the contracts appear in the documentation pages.

 Update: the xml comment generation is now available for download!

The Research in Software Engineering team (RiSE) coordinates Microsoft's research in Software Engineering in Redmond, USA.


Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
  • I've already run into several cases where I've wondered why a method had no contracts on it (they were inherited from an interface). Having them automatically listed will definitely be a big help.


    The xml documentation is also sure to be useful for MSDN, but having contracts show up in intellisense tooltips would be much handier.

  • Allan LindqvistaL_ Kinect ftw

    cool, but i agree, its good but the way its implemented it wont show up in intellisense.. you could perhaps have an options to paste in the comments in the summary/params element instead of as new elements Smiley


    what i dont get is how the contracts are turned into expressions, Requires() just takes a bool, not Expression<bool> (right?) how does that work? Smiley

  • Adam SpeightAdam​Speight2008 The Bandito Coder

    From my understanding of how Code Contracts works is that they get rearranged at compiletime into the required positions, not at runtime which would require a Expression<Bool>.


    Being a compile-time operation, the mechanics of code contract could use T4. (Is the correct?)

    For example: A Requires get moved to the being of Method, A Ensure at the End.


    The Result of an Expression is prodominatly a Boolean, but could be an Exception.


    Lenght < 10 think as "Is Length < 10?" the possible answers are TRUE, FALSE (or Exception)

  • dkallendkallen JoJo, our pet rat

    Does the the "green bubble" Daryl is working on serve your goal of seeing the contracts when you inherit? I am a bit unclear when/where the green bubble appears.


    By the way, I'm glad Microsoft is hiring talented high school interns. I wish other business would give young people more chances like this. It's really important to their professional and personal growth.

  • Peli de Halleuxpeli Peli

    Neither of those (Expression Trees or T4). Code Contracts use CCI (http://ccimetadata.codeplex.com ) to read the MSIL byte stream and decompile the expressions and rewrite the bodies to insert runtime checks.

  • At aL_:

    You're exactly right, you can get them to show up by patching into the summary tag, in fact I've already got code for CCDoc that does just that. However, with VS2010 we can do even better, with some of their new extensibility features you can now add additional information into an IntelliSense QuickInfo bubbles, however this won't be available until beta 2.


    At dkallen:

    You’re right, the "green bubble" is meant to help you when you're implementing an inherited method that has contracts so you know exactly what those contracts are. Our "green bubble" will only appear if you’re inheriting from an interface/class that is in a compiled assembly (i.e. not in your current project) because the code contracts tools work by decompilation.

  • Peli de Halleuxpeli Peli

    The problem with patching summary tag is that it does not work for projects loaded in the solution. The C# parser does not read the xml doc file and uses some internal parse tree.

  • Allan LindqvistaL_ Kinect ftw

    i see Smiley does that mean that the variable names are lost if the dll is not built with debug info? will CC use generic variable names in that case or what? (in contract violation exceptions i mean)



    ok cool Smiley yeah, MEF is pretty powerful stuff. i didnt know you could plug into the intellisense bubbles as well though. (you are using MEF right?)

  • The CodeContracts tool chain builds its own "contracts" dll (i.e. filename.contracts.dll) that contains all the contracts information that CCDoc or other contract tools need and it must be present in order for them to work. This contracts dll is automatically built if you check the "Build a Contract Reference Assembly" in your CodeContracts settings in VS (similar to the "Emit contracts into XML doc file" option I talked about in the film).


    Yes, it's all done with MEF. You can't currently plug into the IntelliSense bubbles, but hopefully in beta 2 or so you will be able to Smiley

  • Yes, the idea is that the bubbles (adornments) should show up when you are writing an override of a virtual method in a supertype or an implementation of an interface method and you are going to inherit a contract from the overidden method or the interface method (respectively). Otherwise you might not be aware of it.

  • Hi guys,


    I must say that you have done a great job with code contracts.


    But unfortunately, I am having some problems with this Xml Documentation from Code Contracts. I have taken the same steps as Daryl on this video, but I am not able to get the contract tags into the xml documentation file. I am using 1.2.21023.14 version and tried it with both VS2008 and VS2010 Beta 2. There are no errors but simply contracts are not shown.


    How should I resolve this issue?

  • Peli de Halleuxpeli Peli

    Post your questions on code contracts at



Remove this comment

Remove this thread


Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.