Skip to content

Rules with transitive linked facts can cause duplicate key exception #180

@snikolayev

Description

@snikolayev

A chain of rules yielding linked facts could cause an exception, when the asserted fact is updated, when one of the calculated facts implements IEquatable interface.
This is because a new version of the fact is yielded before the previous version is retracted.

System.ArgumentException
An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at NRules.WorkingMemory.AddFact(Fact fact)
   at NRules.WorkingMemory.AddLinkedFact(Activation activation, Object key, Fact fact)
   at NRules.Session.InsertLinked(Activation activation, Object key, Object fact)
   at NRules.ActionContext.InsertLinked(Object key, Object fact)
   at NRules.RuleAction.Invoke(IExecutionContext executionContext, IActionContext actionContext, Object[] arguments)
   at NRules.ActionInvocation.Invoke()
   at NRules.ActionExecutor.Execute(IExecutionContext executionContext, IActionContext actionContext)

The solution is to unlink linked facts that are queued for retraction, after each rule firing.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions