elsa-core: Bug: Elsa 2.0 MongoDb Deserializing
When loading workflow instances I get the following error.
An error occurred while deserializing the Activities property of class Elsa.Models.WorkflowInstance: An error occurred while deserializing the Output property of class Elsa.Models.ActivityInstance: Unknown discriminator value 'FinishOutput'.
I already know the cause of this: https://stackoverflow.com/a/43312423
BsonClassMap.RegisterClassMap<FinishOutput>(); will fix the problem.
But it will probably happen more often. It would be best to register the classes centrally, so that in Elsa.Persistence.MongoDb only the central place has to be read and thus no dependencies to other projects exist.
I just don’t know yet where it is nicest and how to name it best.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (13 by maintainers)
Commits related to this issue
- WIP #552 - Refactor test logic (reusability) This refactor of integration test logic is to boost its reusability. Moving some functionality to attributes & customization classes means I can reuse el... — committed to craigfowler/elsa-core by craigfowler 3 years ago
- WIP #552 - Add unit test to repro Actually, this unit test does not repro the issue. Frustratingly I can't get it to save the executed workflow into MongoDB at all. I see workflow execution logs bei... — committed to craigfowler/elsa-core by craigfowler 3 years ago
- Merge branch 'feature/552-mongodb-serialization' into feature/728-WorkflowInstances-not-persisting This brings some of the tests I was writing for #552 into this branch. That's where I first repro'd... — committed to craigfowler/elsa-core by craigfowler 3 years ago
- BREAKING: Update MongoDB provider with support for object derivatives Fixes #552 — committed to elsa-workflows/elsa-core by sfmskywalker 3 years ago
- BREAKING: Update MongoDB provider with support for object derivatives Fixes #552 — committed to elsa-workflows/elsa-core by sfmskywalker 3 years ago
@Juandavi1 This should be fixed with the latest preview packages available on MyGet and of course in
master. Please feel free to reopen if you can still reproduce this issue with the latest version and repro steps. Thanks!Tricky problem, here’s why:
BsonClassMap.RegisterClassMap<T>.One not-so-great solution I can think of is to require the host application to register these types, like so:
Which is far from ideal of course, because now the user needs to understand what types to register, depending on what activity packages they use.
So what we might do instead is let Newtonsoft.Json take care of object serialization, which does not require “known types” to be registered.
I tried it and it works wonders, but it also means that it will break existing MongoDB databases where they basically need to wipe their DB.
No longer reproducible as-described
Hi @Rafael94 - I’ve been looking into this to try and address it in Elsa 2.0. After some exploration, I’m not sure that this requires any code change for Elsa 2.0 and has been “fixed by accident” during other work on the various models used to persist information in the database.
I’ve got a test-case in Elsa 2.0 which proves that a workflow instance may be persisted and then read-back from MongoDb. That’s a fairly minimal example, but you can see that a workflow may be started, suspended, persisted and then retrieved OK. The property of a
WorkflowInstancewhich is noted in your original issue report:Activitiesno longer exists, and its replacements/conceptual equivalents store only objects that have primitive properties and which are not polymorphic.I have also had a look around at some of the other models which are persisted into the data store and they have been refactored in similar ways. If you can create a reproduction case for this in Elsa 2.0 then please share it, but overall I think this one has actually been “fixed for free”.
I’ll leave this issue open for a while, in case anybody finds a reproduction case, but it’s my belief that we don’t need to make any code changes here. If this is still open when Elsa 2.0 is due for release, my recommendation would be to close it.
Two new issues created for those aside-tasks: #650 and #651.