I am using VS2010 Ultimate with Code Contracts. After getting unexpected runtime behavior, I reviewed the source code in reflector and realized that my invariants are not being compiled. The generated __ContractsRuntime
class only contains definitions for Assert
, Ensures
, ReportFailure
, Requires<TException>
and TriggerFailure
. I am using the [ContractInvariantMethodAttribute]
over a single private method per type for all my Contract.Invariant(...)
clauses. I have full contract checking with "Standard Contract Requires" configured as the assembly mode.
My assembly file contains the following assembly attribute:
[assembly: RuntimeContracts(RuntimeContractsFlags.InheritContracts | RuntimeContractsFlags.StandardMode | RuntimeContractsFlags.ThrowOnFailure | RuntimeContractsFlags.Assumes | RuntimeContractsFlags.Asserts | RuntimeContractsFlags.Invariants | RuntimeContractsFlags.Ensures | RuntimeContractsFlags.Requires | RuntimeContractsFlags.RequiresWithException | RuntimeContractsFlags.LegacyRequires)]`
Does anyone have this issue or any insight as to why my invariants are not working as expected?