Monday, September 07, 2009

Diving & Exploration

Gems which I found last month :
  1. Scott Hanselman's 2009 Ultimate Developer and Power Users Tool List for Windows
    If you are a MS developer you would know Mr. Hanselman and this popular post series wherein he lists out some of the most powerful tools for windows.
  2. 50 Windows 7 tips, tricks and secrets
    One stop shop of all the cool features of Windows 7.
  3. Cloaking your ASP.NET MVC Web Application on IIS 7
    Here Howard explains the security aspects of a publish facing web application and how we can change the header information of an MVC application on a WISA (Windows, Internet Information Services, SQL Server, ASP.NET) Platform
  4. The role of a hands-on software architect
    This is an excellent article from ‘coding the architecture’ community explaining - “What should a hands-on software architect do?” in various aspects of project life cycle.
  5. 10 Things Every Software Architect Should Know
    This is an excerpt from the Richard Monson-Haefel’s 97 Things Every Software Architect Should Know,  where he collaborated with over two dozen authors to collect 97 axioms of software architecture

Friday, September 04, 2009

SOS debugging extension on 64bit Applications

Recently I got into a problem running the SOS on a 64bit Virtual Machine. Visual Studio gave the following message :

Microsoft Visual Studio
Error while trying to run project: Unable to start program '<app path>'.

The debugger does not support debugging managed and native code at the same time on this platform.

Binging’ around I found that there is a known issue in Visual Studio 2008 Mixed Mode Debugging for 64bit Applications. Since to run the SOS we have to ‘Enable unmanaged code debugging’, hence the issue.
The only way I could make it working with VS 2008 was by changing the Platform Configuration to x86.

Tuesday, September 01, 2009

Spec# - Code Contracts in .Net 4.0

Spec# is a formal language for API contracts (influenced by JML, AsmL, and Eiffel), which extends C# with constructs for non-null types, preconditions, postconditions, and object invariants.”

Code Contracts is a library which provides a language-agnostic way to express coding assumptions in .NET programs and would be included as part of the base class library in .NET 4.0. The contracts can be called as a subset of Spec# and take the form of preconditions, postconditions, and object invariants”

Let’s see how an we leverage code contracts. After installing the code contracts create a new VS Project (I used a console app here) and add the reference to ‘Microsoft.Contracts.dll’, which you would find in ProgramFiles\Microsoft\Contracts\PublicAssemblies\v3.5. Then enable the Static Contract checking in VS (which is the whole purpose of contracts, validating things at compile time rather than runtime). Goto –> Project Properties and you check the options as shown below :


Now lets see some quick examples of precoditions, postconditions and object invariants . . .

Preconditions - What does it expect? As the name suggests, precoditions are contracts to ensure that the expected data is provided while performaing an operation.
e.g. :
Postconditions - What does it guarantee? Postconditions are contracts to ensure certain conditions are met just before exiting an operation.
e.g. :
Object Invariants - What does it maintain? Object invariants express the conditions under which the object is in a good state.
e.g. :
(In the above customer class we have an invariant contract to check that the ID should always be greater than zero, which is being called after each public method calls and validated)
Interface Contracts
Code contracts can also be applied to Interface methods by creating a sealed classes as shown below :

There are many other methods in the Contract class which could be used in many other scenarios. Checkout the documentation of this library and Matthew’s blog post for more details.