You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to add metadata to events (see #780, IMO this should be supported by the framework at a basic level), and went the route of adding a wrapper around each event, as such:
public class Envelope<T>
{
public T Value { get; set; }
public Guid ExecutingUserId { get; set; }
}
public class Created
{
public Guid Id { get; set; }
}
public class Updated
{
public String UpdateValue { get; set; }
}
Attempting to load a stream with two different events (Envelope<Created> and Envelope<Updated>) results in all events attempting to be deserialized using the type of the first event (Envelope<Created>).
The error that surfaces is a JSON parsing issue (JsonReaderException: Unexpected character encountered while parsing value), but I ran intermediate code under the JSON parser and discovered that the second event is attempting to be deserialized using the Type of the first event.
Troubleshooting I've done:
Fetch just the second event (Envelope<Updated>) to verify that there's no inherent problem with that record. Using QueryAllRawEvents() and skipping the first record, it deserializes correctly and I get a nice Envelope<Updated>
Remove my Envelope<> wrapper and just persist the events (maybe my code is the problem). This works, which means that the problem is probably down in the Marten framework itself.
Hopefully that's useful debugging information - if you can point me in the right direction I may have a go at fixing it myself.
The text was updated successfully, but these errors were encountered:
@eouw0o83hf It's not a serialization error per se, it's just that Marten is probably being too naive about how it stores the event type name. Closed generic event types really wasn't something we anticipated here. That's really not a case I'm excited about supporting because the reflection wok around that is always a huge mess.
It'd be easier to deal with this with a simple layer supertype for your event classes, even without waiting for us to add the event metadata
@jeremydmiller I'll do some more research, but I seem to remember getting correct types out if I queried the data in different ways, which led me to believe that Types are being persisted correctly but maybe reinstantiated naively.
I wound up going the supertype route, it's probably an overall less-complex way to deal with it.
I have some time coming up to get the Marten solution setup locally, I'll see if I can knock this out.
I'm trying to add metadata to events (see #780, IMO this should be supported by the framework at a basic level), and went the route of adding a wrapper around each event, as such:
Code to manage event streams:
Events commit happily, updated projections correctly, and even persist the correct event type to the database.
Querying the event stream throws an exception though. Stream loading code:
Attempting to load a stream with two different events (
Envelope<Created>
andEnvelope<Updated>
) results in all events attempting to be deserialized using the type of the first event (Envelope<Created>
).The error that surfaces is a JSON parsing issue (
JsonReaderException: Unexpected character encountered while parsing value
), but I ran intermediate code under the JSON parser and discovered that the second event is attempting to be deserialized using the Type of the first event.Troubleshooting I've done:
Envelope<Updated>
) to verify that there's no inherent problem with that record. UsingQueryAllRawEvents()
and skipping the first record, it deserializes correctly and I get a niceEnvelope<Updated>
Envelope<>
wrapper and just persist the events (maybe my code is the problem). This works, which means that the problem is probably down in the Marten framework itself.Hopefully that's useful debugging information - if you can point me in the right direction I may have a go at fixing it myself.
The text was updated successfully, but these errors were encountered: