question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Elsa 2.0 MongoDb Deserializing

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
sfmskywalkercommented, Jul 3, 2021

@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!

1reaction
sfmskywalkercommented, May 27, 2021

Tricky problem, here’s why:

  • When using MongoDB, we need to register any and all types that are potentially stored in a workflow instance using BsonClassMap.RegisterClassMap<T>.
  • We have many modules with activities that potentially store something within a workflow instance.
  • None of these modules should have a dependency on MongoDB.
  • The MongoDb provider itself should also not have a dependency on any of the activity modules (such as Elsa.Activities.Http).

One not-so-great solution I can think of is to require the host application to register these types, like so:

public class Startup
{
    public Startup()
    {
        BsonClassMap.RegisterClassMap<HttpRequestModel>(cm => cm.AutoMap());
    }
}

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with deserialization - Drivers & ODMs
I have a class with a Point class field called “APoint”. The document is created and APoint is an object with X and...
Read more >
4.4 Changelog
SERVER-68115 Bug fix for "elemMatchRootLength > 0" invariant trigger ... SERVER-40865 The ShardServerCatalogCacheLoader does not serialize read operations ...
Read more >
MongoDB .NET Driver not deserializing for collection
Mongo.GardaSubdistrictBoundaryMongo: An error occurred while deserializing the Coordinates property of class VisualStatsPoCAPI.Repositories.
Read more >
Release notes — JaVers Documentation
1092 Fixed bug when deserializing Diff from JSON: MALFORMED_CHANGE_TYPE_FIELD : no such Change type - InitialChange . 6.1.0. released on 2021-04-25. 1080 New ......
Read more >
[Solved]-Deserialize object as an interface with MongoDB C# ...
In resume, this exception error is related to structs deserialization, not with interfaces deserialization. Anyway, it is a real problem, and the second...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found