JasperFx / wolverine

Supercharged .NET server side development!
https://wolverinefx.net
MIT License
1.25k stars 137 forks source link

IEvent<T> is not serializable #870

Closed anhtin closed 6 months ago

anhtin commented 6 months ago

Describe the bug Handlers can't react to Marten.IEvent<T> messages when the endpoint is configured to be durable since Marten.IEvent<T> is not serializable.

To Reproduce

  1. Integrate Wolverine with Marten; it doesn't matter whether you use .EventForwardingToWolverine or .PublishEventsToWolverine.
  2. Declare a Wolverine handler that reacts to a Marten.IEvent<T>, e.g.:
    public static class SomeHandler
    {
    public static object Handle(IEvent<SomeEvent> martenEvent)
    {
        Console.WriteLine(martenEvent.StreamKey);
    }
    }
  3. Configure the relevant endpoint to be durable, e.g. options.Policies.UseDurableLocalQueues()
  4. Append the Marten event, T, to an event stream.

Expected behavior SomeHandler executes and outputs the stream key.

Actual behavior Serialization of Marten.IEvent<T> fails with the following exception: System.NotSupportedException: Serialization and deserialization of 'System.Type' instances is not supported. Path: $.EventType.

jeremydmiller commented 6 months ago

@anhtin I think I'm going to cheat and make this public w/ a no arg ctor in Marten, then close this w/ a test.

Didn't make the 2.7 cut, but will the next release this week