Skip to content

InvalidProgramException while trying coyote on my library. #433

@Kuinox

Description

@Kuinox

Hello,
I wanted to test out coyote to try to find bugs in my MQTT Library.

Sadly it looks like the IL rewrite has a problematic bug:

Unhandled exception. System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at CK.MQTT.Client.Tests.Helpers.ApplicationMessageExtensions.PublishAsync(TestMQTTClient this, ApplicationMessage message)
   at CK.MQTT.Client.Tests.CoyoteTests.simple_publish_qos2_works_Async()
   at Microsoft.Coyote.Runtime.CoyoteRuntime.<>c__DisplayClass59_0.<RunTestAsync>b__0() in D:\a\1\s\Source\Core\Runtime\CoyoteRuntime.cs:line 373
   at Microsoft.Coyote.Runtime.CoyoteRuntime.<>c__DisplayClass62_0.<ScheduleOperation>b__0() in D:\a\1\s\Source\Core\Runtime\CoyoteRuntime.cs:line 467

The corrupted method do something a bit unusual:

        public static ValueTask<Task> PublishAsync( this TestMQTTClient @this, ApplicationMessage message )
            => @this.PublishAsync( message.Topic, message.QoS, message.Retain, message.Payload );

And the IL Diff:

"FullName": "CK.MQTT.Client.Tests.Helpers.ApplicationMessageExtensions",
"Methods": [
  {
    "Name": "PublishAsync",
    "FullName": "System.Threading.Tasks.ValueTask`1<System.Threading.Tasks.Task> CK.MQTT.Client.Tests.Helpers.ApplicationMessageExtensions::PublishAsync(CK.MQTT.Client.TestMQTTClient,CK.MQTT.Client.ApplicationMessage)",
    "Instructions": [
      "[-] IL_001e: ret",
      "[+] IL_001e: ldstr \"CK.MQTT.SmallOutgoingApplicationMessageExtensions.PublishAsync\"",
      "[+] IL_0023: call System.Threading.Tasks.ValueTask`1<TResult>& Microsoft.Coyote.Runtime.ExceptionProvider::ThrowIfReturnedValueTaskNotControlled<System.Threading.Tasks.Task>(System.Threading.Tasks.ValueTask`1<TResult>&,System.String)",
      "[+] IL_0028: ret"
    ]
  }
]

If you need to reproduce it, I made a branch on my repo:
https://github.com/signature-opensource/CK-MQTT/tree/testing-coyote

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-binary-rewritingIssues related to binary rewritingbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions