BadImageFormatException on any async generic ensures RRS feed

  • Question

  • Any method of the following form:

    public Task<T> DoSomethingAsync<T>()

    { Contract.Ensures(!ReferenceEquals(Contract.Result<T>(), null)); // TODO Implementation }

    With the runtime rewriter enabled on postconditions results in a BadImageFormatException:

    An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

    One example:
    private static Task<T> SafeFromResult<T>(T val)
        Contract.Requires(!ReferenceEquals(val, null));
        Contract.Ensures(!ReferenceEquals(Contract.Result<T>(), null));
        return Task.FromResult(val);
    This is using code contracts version 1.6.60617.15.
    Friday, August 1, 2014 10:54 AM