Explicit nodes internal error, dereferencing a non-pointer

Good morning forum,
I am in the process of starting my journey in the explicit nodes world. Until now I have managed to get a control on the node to show an icon and to define the node itself.
The problem now is to get it to work! Can anyone help me to understand what am I missing? Any better documentation to look at?

Can’t get it to work properly and to use the default values…
The same node in ZeroTouch version works perfectly.

using AECOM.Civil;
using DynAECOMo.UI.Controls;
using Dynamo.Controls;
using Dynamo.Graph.Nodes;
using Dynamo.Wpf;
using Newtonsoft.Json;
using ProtoCore.AST.AssociativeAST;
using System;
using System.Collections.Generic;
using System.Linq;

namespace DynAECOM.Nodes.Landxml
{
    [NodeCategory("DynAECOM.Landxml")]
    [NodeName("OpenDocument")]
    [NodeDescription("Open a landxml document")]
    [InPortTypes("string", "double", "double")]
    [InPortNames("filePath", "easting", "northing")]
    [OutPortTypes("AECOM.Civil.LandXml")]
    [OutPortNames("landxml")]
    public class OpenDocument : NodeModel
    {
        public LandXml Landxml { get; set; }
        public double Easting { get; set; }
        public double Northing { get; set; }

        [JsonConstructor]
        public OpenDocument(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPorts) : base(inPorts, outPorts)
        {

        }

        public OpenDocument()
        {
            //InPorts.Add(new PortModel(PortType.Input, this, new PortData("File Path", "The file path for the landxml file")));
            //InPorts.Add(new PortModel(PortType.Input, this, new PortData("Easting", "Easting project base point [Default is 0.0]")));
            //InPorts.Add(new PortModel(PortType.Input, this, new PortData("Northing", "Northing project base point [Default is 0.0]")));
            //OutPorts.Add(new PortModel(PortType.Output, this, new PortData("Landxml", "The landxml parsed object")));
            
            RegisterAllPorts();
            ArgumentLacing = LacingStrategy.Disabled;


        }

        public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
        {
            
            // If any of the input nodes is not connected, assign output node 0 a null node return value
            if (!InPorts[0].Connectors.Any() || !InPorts[1].Connectors.Any() || !InPorts[0].Connectors.Any())
            {
                return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildNullNode()) };
            }

            AssociativeNode inputNode = AstFactory.BuildFunctionCall(
                new Func<string, double, double, LandXml>(LandxmlFunctions.OpenLandxmlDocument),
                new List<AssociativeNode> { inputAstNodes[0], inputAstNodes[1], inputAstNodes[2] }
                );

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

    }

    public class OpenDocumentNodeView : INodeViewCustomization<OpenDocument>
    {
        public void CustomizeView(OpenDocument model, NodeView nodeView)
        {
            var control = new OpenControlUI();
            nodeView.inputGrid.Children.Add(control);
            control.DataContext = model;
        }

        public void Dispose()
        {
        }
    }
}

And then the function

using AECOM.Civil;
using Autodesk.DesignScript.Runtime;

namespace DynAECOM
{
    public class LandxmlFunctions
    {
        private LandxmlFunctions() { }

        [IsVisibleInDynamoLibrary(false)]
        public static LandXml LandXml { get; set; }
        [IsVisibleInDynamoLibrary(false)]
        public static double Easting { get; set; }
        [IsVisibleInDynamoLibrary(false)]
        public static double Northing { get; set; }

        [IsVisibleInDynamoLibrary(false)]
        public static LandXml OpenLandxmlDocument(string filePath, double easting = 0, double northing = 0)
        {
            LandXml = new LandXml(filePath);
            Easting = easting;
            Northing = northing;
            return LandXml;
        }
    }
}

And finally a portion of the class which literally does nothing but opening a file

public class LandXml
    {
        /// <summary>
        /// The XML file path
        /// </summary>
        public string FilePath { get; set; }
        public XmlDocument Document { get; private set; }
        public Application Application => GetApplication();
        public ICollection<Alignment> Alignments => GetAlignments();
        public ICollection<Surface> Surfaces => GetSurfaces();

        public LandXml(string filePath)
        {
            this.FilePath = filePath;
            this.Document = new XmlDocument();
            this.Document.Load(this.FilePath);
        }
}

What does the error say? Could be random, but try using 0.0 for the E & N.

Nope, doesn’t work. When I debug the code it looks like it never enters the function

make sure your function and your nodeModel are defined in different assemblies.

They are in two different assemblies and also the landxml class is on a third assembly.

probably not your error, but looks like maybe a copy paste bug in your connector check.

Also - something is wrong with your function call - you define a Func<string,double,double> this means the function you call takes 1 double, and 1 strings, and returns a double, thats not the signature of the function you are calling, and it’s not the structure of the data you pass -
define your func more accurately - I think it would be Func<string,double,double,LandXML>

1 Like

Hi,
The signature looks right to me (I can see LandXML after string,double,double)
As for the connector check, that was just a typo that didn’t effect the execution and was already fixed.
To me it looks like is never entering the function at all.
No idea what the problem is?!

Is there a case conflict here with your variable and the type?

Nope and that doesn’t even get touched by this function.

ah sorry, missed the last param - hmm -

how are you loading your node and the other binaries? Are you sure the other assemblies are loaded?

Do you have the project setup on GitHub so that the code can be built, the source inspected and the issue reproduced?

Have you looked at the nodes in DynamoSamples repo? Not sure what docs are using currently.

Hi @Michael_Kirschner2, adding you to the repository.
Cheers,
Cesare

1 Like

It will be very interesting to understand why it doesn’t work. I have tried to create an additional node with just 2 doubles input and one double output and that doesn’t work too.
And I have followed this example
DynamoNodeModelsEssentials/EssentialsMultiply.cs at master · nonoesp/DynamoNodeModelsEssentials (github.com)

1 Like

Ok thanks to @Michael_Kirschner2 I realized that it wasn’t wrong the way the node was written, but the problem was in the name of the library in the pkg.json calling for the wrong library!
Thanks for the help…

2 Likes