Custom NodeModel Error: Dereferencing a non-pointer

Hello,
I’m attempting to create a very simple custom NodelModel, but with no success, an Error: Dereferencing a non-pointer keeps apperaing. Dynamo version: 1.0.0.1180.

If no input is connected, the node shows gray as normal, but if two numbers are connected as input I get:

I’ve been following the same structure of other Dynamo nodes, so I cannot explain myself what’s wrong or missing. The node simply multiplies two numbers, below the full code:

using System;
using System.Collections.Generic;
using Dynamo.Graph.Nodes;
using ProtoCore.AST.AssociativeAST;

namespace TestNodeModel
{
  [NodeDescription("Test Node")]
  [NodeName("TestNode")]
  [NodeCategory("TestCategory")]
  [InPortNames("A", "B")]
  [InPortTypes("double", "double")]
  [InPortDescriptions("Number A", "Numnber B")]
  [OutPortNames("Output")]
  [OutPortTypes("double")]
  [OutPortDescriptions("AxB")]
  [IsDesignScriptCompatible]
  public class TestNodeModel : NodeModel
  {
    public TestNodeModel()
    {
      RegisterAllPorts();
    }

    public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
    {
      if (!HasConnectedInput(0) || !HasConnectedInput(1))
      {
        return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
      }

      var functionCall =
        AstFactory.BuildFunctionCall(
          new Func<double, double, double>(DoCalc),
          new List<AssociativeNode> { inputAstNodes[0], inputAstNodes[1] });

      return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), functionCall) };
    }

    public static double DoCalc(double a, double b)
    {
      return a * b;
    }
  }
}

Disclaimer: I know practically no C#

However, built a dll using the exact same code posted above and imported it in the latest daily build (1.1)
Worked for me.

Vikram, thanks for your help.
It looks like you have loaded the dll as a ZeroTouch node and accessed the DoCalc method diretly, while I’m testing it as a NodeModel for which you need the whole package.

I’ve attached a copy of it if you want to test: https://www.dropbox.com/s/ultjbotv57p02sp/TestNodeModel.zip?dl=0

SOLUTION from Ian: the DoCalc method has to be in a separate assembly.

2 Likes

Sharing a repo containing the source code fore those interested: https://github.com/teocomi/HelloDynamo
The separate assembly has to be loaded into dynamo directly, so it has to be declared the pkg.json file as well.

1 Like