0

Is it possible to use Code Contracts in Dynamics CRM 2011 Workflows?
The Contract Entity has the same name as Contract in System.Diagnostics.Contracts, but code contracts can still be used like this

 System.Diagnostics.Contracts.Contract.Requires(i < 5);

I get this Warning:

Method 'CRV.AssociateEmail.Execute(System.Activities.CodeActivityContext)' overrides 'System.Activities.CodeActivity.Execute(System.Activities.CodeActivityContext)', thus cannot add Requires.

ccellar
  • 10,326
  • 2
  • 38
  • 56
Bvrce
  • 2,170
  • 2
  • 27
  • 45

1 Answers1

1

This is not an issue in regards to CRM.

You are basically overwriting the Execute method of CodeActivity when you are creating a new workflow activity. You can't add contracts at this point.

See this question for a explanation: Why can't I add Contract.Requires in an overridden method? And for more details: http://stefanoricciardi.com/2009/07/17/code-contracts-and-inheritance/

Community
  • 1
  • 1
ccellar
  • 10,326
  • 2
  • 38
  • 56
  • Which shouldn't speak against using Code Contracts in CWAs in general, though, just in other classes than the activity itself. Requiring anything from the `Execute()` parameter that is always controlled by the CRM platform itself is a bit pointless anyway. – TeaDrivenDev Jun 10 '13 at 13:14