Skip to content

System.BadImageFormatException: Bad IL Format when monitoring events on .NET Core 3.0-preview5 #1047

@Wildenhaus

Description

@Wildenhaus

Description

FluentAssertions throws a BadImageFormatException when invoking a monitored event. This only occurs in the .NET Core 3.0 preview.

Complete minimal example reproducing the issue

[TestClass]
public class Repro
{
   public delegate void EventDelegate();

   public class Tester
   {
      public event EventDelegate TestEventDelegate;
      public event EventHandler TestEventHandler;

      public void RaiseEventDelegate()
      {
         TestEventDelegate?.Invoke();
      }

      public void RaiseEventHandler()
      {
         TestEventHandler?.Invoke( this, EventArgs.Empty );
      }
   }

   [TestMethod]
   public void TestRaiseEventDelegate()
   {
      var tester  = new Tester();
      var monitor = tester.Monitor();

      tester.RaiseEventDelegate();

      monitor.Should().Raise( nameof( Tester.TestEventDelegate ) );
   }

   [TestMethod]
   public void RaiseEventEventHandler()
   {
      var tester  = new Tester();
      var monitor = tester.Monitor();

      tester.RaiseEventHandler();

      monitor.Should().Raise( nameof( Tester.TestEventHandler ) );
   }
}

Expected behavior:

EventHandlerFactory should emit a handler that does not cause a BadImageFormatException to be thrown.

Actual behavior:

A BadImageFormatException is thrown when the event is invoked.

Versions

  • Which version of Fluent Assertions are you using?
    FluentAssertions v5.6.0 via NuGet

  • Which .NET runtime and version are you targeting?
    .NET Core 3.0-preview5

Additional Information

Have not looked into it. The exception is thrown immediately upon invoking the event. Bug does not occur in earlier versions of .NET Core (tested with 2.2).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions