Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

"Malformed contract section" when rewriting async methods #112

@roji

Description

@roji

Encountered while building Npgsql:

Severity    Code    Description Project File    Line
Error   CC1017  Malformed contract section in method 'Npgsql.NpgsqlBuffer+<SkipAsync>d__78.MoveNext'    Npgsql  C:\projects\npgsql\src\Npgsql\NpgsqlBuffer.cs   600
Error   CC1017  Malformed contract section in method 'Npgsql.NpgsqlDataReader+<GetFieldValueInternalAsync>d__133`1.MoveNext'    Npgsql  C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs   1861
Error   CC1017  Malformed contract section in method 'Npgsql.NpgsqlLargeObjectStream+<SeekAsync>d__34.MoveNext' Npgsql  C:\projects\npgsql\src\Npgsql\NpgsqlLargeObjectStream.cs    300
Error   CC1017  Malformed contract section in method 'Npgsql.NpgsqlLargeObjectStream+<SetLengthAsync>d__36.MoveNext'    Npgsql  C:\projects\npgsql\src\Npgsql\NpgsqlLargeObjectStream.cs    300
Error       The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite.exe" "@Npgsqlccrewrite.rsp"" exited with code 4. Npgsql      

Note that the files and line numbers are bogus: these async methods are in GeneratedAsync.cs (there's some code generation going on). In any case, the first methods is simply this:

        internal async Task SkipAsync(long len)
        {
            Contract.Requires(len >= 0);
            if (len > ReadBytesLeft)
            {
                len -= ReadBytesLeft;
                while (len > Size)
                {
                    Clear();
                    await EnsureAsync(Size);
                    len -= Size;
                }

                Clear();
                await EnsureAsync((int)len);
            }

            ReadPosition += (int)len;
        }

Am not sure what is causing this: a simple async method with Contract.Requires seems OK...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions