-
Notifications
You must be signed in to change notification settings - Fork 668
Description
I'm getting an unexpected error in 2.0.1, using the Dynamo API on a custom node. The same code was working fine in 1.3.
The error is:
Warning: Dictionary.ByKeysValues operation failed.
Value cannot be null.
Parameter name: first
Dictionary.ByKeysValues operation failed.
The error is thrown when dynamically adding OutPorts to a node. I've create a simplified version of my node, you can use it to replicate the issue.
To replicate it, use the code below to create a custom node, I've tweaked the + sign that's used to add InPorts to actually add OutPorts, but the same error happens when the action is fired by a button on the node UI or by external events. Adding a few ports behaves just fine, but after a while the error shows up without apparent reason.
using Dynamo.Graph.Connectors;
using Dynamo.Graph.Nodes;
using Newtonsoft.Json;
using ProtoCore.AST.AssociativeAST;
using System.Collections.Generic;
namespace Test
{
[NodeName("Test")]
[NodeDescription("Tetst.")]
[NodeCategory("Test")]
[NodeSearchTags("Test")]
[IsDesignScriptCompatible]
public class Test : VariableInputNode
{
[JsonConstructor]
private Test(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
{
ArgumentLacing = LacingStrategy.Disabled;
}
public Test()
{
InPorts.Add(new PortModel(PortType.Input, this, new PortData("In", "")));
RegisterAllPorts();
ArgumentLacing = LacingStrategy.Disabled;
}
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
var associativeNodes = new List<AssociativeNode>();
for (var i = 0; i< OutPorts.Count; i++)
{
associativeNodes.Add(AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(i), AstFactory.BuildStringNode(i.ToString())));
}
return associativeNodes;
}
protected override void AddInput()
{
OutPorts.Add(new PortModel(PortType.Output, this, new PortData("out" + (OutPorts.Count + 1), "")));
RegisterAllPorts();
OnNodeModified(true);
}
protected override string GetInputName(int index)
{
return "item" + index;
}
protected override string GetInputTooltip(int index)
{
return "Layer " + InPorts[index].Name;
}
public override bool IsConvertible
{
get { return true; }
}
protected override void OnConnectorAdded(ConnectorModel obj)
{
base.OnConnectorAdded(obj);
}
}
}
