Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues(4893): try register serializer or skip when already registred … #4894

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

bbenameur
Copy link
Contributor

@bbenameur bbenameur commented Feb 7, 2024

Related to this fix #4886
it appeared that this fix will not resolve the probelem,
because even with a try it will always have a new instance which is totally different from what is registred
see code on MongoDB.Bson.Serialization

 public bool TryRegisterSerializer(Type type, IBsonSerializer serializer)
 {
     if (type == null)
     {
         throw new ArgumentNullException(nameof(type));
     }
     if (serializer == null)
     {
         throw new ArgumentNullException(nameof(serializer));
     }
     EnsureRegisteringASerializerForThisTypeIsAllowed(type);

     if (_cache.TryAdd(type, serializer))
     {
         return true;
     }
     else
     {
         var existingSerializer = _cache[type];
         if (!existingSerializer.Equals(serializer)) // with new() ... it's always a different instance.
         {
             var message = $"There is already a different serializer registered for type {BsonUtils.GetFriendlyTypeName(type)}.";
             throw new BsonSerializationException(message);
         }
         return false;
     }
 }

To fix it:

TryRegisterSerializerOrSkip(typeof(object), new PolymorphicSerializer());
TryRegisterSerializerOrSkip(typeof(Type), new TypeSerializer());
TryRegisterSerializerOrSkip(typeof(Variable), new VariableSerializer());
TryRegisterSerializerOrSkip(typeof(Version), new VersionSerializer());
TryRegisterSerializerOrSkip(typeof(JsonElement), new JsonElementSerializer());

private static void TryRegisterSerializerOrSkip(Type type, IBsonSerializer serializer)
{
	try
	{
		BsonSerializer.TryRegisterSerializer(type, serializer);
	}
	catch (BsonSerializationException ex)
	{
		// should we log the exception ?
	}
}

…8d23d6

issues(4893): try register serializer or skip when already registred  + clean
@bbenameur
Copy link
Contributor Author

Hello @sfmskywalker

@sfmskywalker sfmskywalker merged commit e64a2ea into elsa-workflows:main Feb 7, 2024
2 checks passed
@bbenameur bbenameur deleted the issues(4893) branch February 9, 2024 13:57
@sfmskywalker sfmskywalker added the elsa 3 This issue is specific to Elsa 3 label Feb 9, 2024
@sfmskywalker sfmskywalker added this to the Elsa 3.1 milestone Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
elsa 3 This issue is specific to Elsa 3
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

2 participants