InvalidProgramException with async runtime checks; small repro RRS feed

  • Question

  • When using the IL rewriter to install runtime checking, this code causes an InvalidProgramException:

    static async Task BombContractsAsync<T>(IEnumerable<T> items)
        Contract.Requires(items != null && Contract.ForAll(items, x => x != null));

    Method must be async, and pattern must be "items != null && ForAll(items)". A ForAll by itself does not cause the issue. I'm using 1.5.60911.10, but it has existed for some time (took me a while to pin down the issue).

    Wednesday, November 27, 2013 4:36 PM

All replies

  • Is Contracts still being maintained? The lack of response is unfortunate, this tool has so much potential.
    Friday, March 28, 2014 3:31 PM
  • I run into a similar issue. Here is a simple program to reproduce it. The version of CodeContracts is 1.6.60505.10. The method must be async, the expression in Contract.Requires must contain '||' or '&&' operators and the program must be built under Release. 

    using System;
    using System.Diagnostics.Contracts;
    using System.Threading.Tasks;
    namespace ConsoleApplication3 {
    	class Program {
    		static void Main(string[] args){
    		public static async Task F(int count){
    			Contract.Requires<ArgumentOutOfRangeException>(count != 0 || count == 1);

    Tuesday, May 27, 2014 8:35 AM
  • Identical issue here - having this contract and building in release gives me an InvalidProgramException

    Contract.Requires(addressType == "X" || addressType == "Y");

    Latest version of code contracts

    Wednesday, July 16, 2014 12:28 AM
  • Hi Guys

    This is still occurring. Today we had this code:

    Contract.Requires(field.FieldTypes != null && field.FieldTypes.Count() == 1);

    Caused exactly the same exception in Release mode only.

    No async is involved.

    Please look at fixing this - we are on the latest version of contracts.

    We are on code contracts 1.7.10908.11

    Friday, November 28, 2014 1:08 AM
  • Can we please have an update on this?
    Tuesday, September 22, 2015 10:45 PM