Search code examples
c#.net-4.5code-contractsasync-awaitc#-5.0

Code Contracts + Async in .NET 4.5: "The method or operation is not implemented"


I receive the following compilation error from ccrewrite when using Code Contracts 1.4.51019.0 in VS2012 on Windows 7 x64: "The method or operation is not implemented."

It appears to be caused by a combination of property accessors and the use of async methods which lack an inner await.

Reproduction steps:

Create a new class library with 'Full' Runtime Contract Checking enabled:

namespace CodeContractsAsyncBug
{
    using System.Threading.Tasks;

    public class Service
    {
        // Offending method!
        public async Task ProcessAsync(Entity entity)
        {
            var flag = entity.Flag;
        }
    }

    public class Entity
    {
        public bool Flag { get; set; }
    }
}

Has anyone else experienced this?


Solution

  • This appears to be fixed in version 1.5 of Code Contracts.