6

The following code:

Contract.Requires<ArgumentException>(command != null, Resources.Messages.CommandNotSpecified);

calls

Contract.AssertMustUseRewriter (ContractFailureKind kind, System.String message)

which seems to be caused by not configuring Code Contracts to use runtime contract checking, if you were using Visual Studio.

the article @ http://devjourney.com/blog/code-contracts-part-2-preconditions/ implies that the code produced without runtime checking configured is:

public static void Requires<TException>(bool condition)
where TException: Exception
{
    AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires<TException>");
}

Does anybody know what to do in MonoDevelop so that the contract works as expected?

The exact exception I'm getting is:

2012-11-13 23:33:24.815 StickX[339:c07] mvx: Diagnostic:  34.46 Exception masked NotImplementedException: The requested feature is not implemented.
      at System.Environment.FailFast (System.String message) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Environment.cs:821 
  at System.Diagnostics.Contracts.Contract.AssertMustUseRewriter (ContractFailureKind kind, System.String message) [0x00011] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Diagnostics.Contracts/Contract.cs:83 
  at System.Diagnostics.Contracts.Contract.Requires[ArgumentException] (Boolean condition, System.String userMessage) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Diagnostics.Contracts/Contract.cs:271 
skolima
  • 31,963
  • 27
  • 115
  • 151
  • Could you include the exact exception you're seeing? – Chris Nov 13 '12 at 20:56
  • 1
    You must use the rewriter, which is only available on Windows at the moment. I guess if you really wanted to, you could compile under Mono and then process the resulting executables with the rewriter, then move them back to your target platform. – porges Nov 14 '12 at 21:10

2 Answers2

4

It's not implemented, so the only thing to make this work would be for you to write the implementation. Mono is an open source project, always happy to take new contributions.

zwcloud
  • 4,546
  • 3
  • 40
  • 69
skolima
  • 31,963
  • 27
  • 115
  • 151
3

For your information the Microsoft CodeContracts are now OpenSource:

https://github.com/CodeContractsDotNet/CodeContracts