Loading dependencies in Dynamo (NodeModel) package?

Hi there!

Working on a Dynamo package implemented through NodeModels. The package itself is a quite thin wrapper around a core DLL, which handles all the heavy load.

Before, the package was developed with all Zero Touch nodes, so just having the core depedency DLL in the package’s bin folder was enough to have it picked up by the package.

On migrating the Nodes to NodeModels, this doesn’t work unless I load the assembly as a node_library, but I am having issues correctly loading the assembly.

My current pkg.json looks like this

{
    "contains_binaries": true,
    "contents": "",
    "dependencies": [],
    "description": "A Dynamo plugin for Robot programming and control. https://github.com/garciadelcastillo/Machina",
    "engine": "dynamo",
    "engine_metadata": "",
    "engine_version": "1.3.0.862",
    "file_hash": null,
    "group": "",
    "keywords": [
        "robot",
        "programming",
        "control",
        "machina",
        "brobot"
    ],
    "license": "",
    "name": "Machina",
    "node_libraries": [
        "Machina, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
        "MachinaDynamo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
    ],
    "repository_url": "https://github.com/garciadelcastillo/Machina",
    "site_url": "",
    "version": "0.4.3"
}

This works fine, but the core DDL Machina shows up on Dynamo’s library, i.e. it is taken as a Zero Touch library.

However, if I declare instead as a dependency:

{
    "contains_binaries": true,
    "contents": "",
    "dependencies": [
        "Machina, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","Machina, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
    ],
    "description": "A Dynamo plugin for Robot programming and control. https://github.com/garciadelcastillo/Machina",
    "engine": "dynamo",
    "engine_metadata": "",
    "engine_version": "1.3.0.862",
    "file_hash": null,
    "group": "",
    "keywords": [
        "robot",
        "programming",
        "control",
        "machina",
        "brobot"
    ],
    "license": "",
    "name": "Machina",
    "node_libraries": [
        "MachinaDynamo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
    ],
    "repository_url": "https://github.com/garciadelcastillo/Machina",
    "site_url": "",
    "version": "0.4.3"
}

I get this error on Dynamo’s console:

Failed to form package from json header.
Newtonsoft.Json.JsonSerializationException: Error converting value "Machina, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" to type 'Greg.Requests.PackageDependency'. Path 'dependencies[0]', line 5, position 72.
Exception encountered scanning the package directory at D:\Dropbox\Jose Luis\code\MachinaDynamo\package\Machina
System.Exception:
D:\Dropbox\Jose Luis\code\MachinaDynamo\package\Machina\pkg.json contains a package with a malformed header.  Ignoring it.
   at Dynamo.PackageManager.PackageLoader.ScanPackageDirectory(String directory)

So, questions:

  • How can I correctly load dependencies of a package using NodeModels?
  • And, how can I load an assembly as a node_library, and completely hide it from Dynamo’s library?

Thanks!

JL

so @GarciadelCastillo first thing: I’m pretty sure dependencies should only point at other packages. - not dlls.

try only labeling your nodeModel library as node_libraries and leave the core dll out of that list - what happens then?

@Michael_Kirschner2 Yes, I tried and it didn’t work, that was the motivation behind this thread :wink:

what does - it didn't work mean?

1 Like

if your first pkg.json file works, you could keep doing that and use the [IsVisibleInDynamoLibrary(false)] or [SupressImport] attributes on the entire namespace or classes in the assembly (maybe)

It means the NodeModels that use the referenced library do not work, they throw a “derreferecing a null object” error, which gets solved if the referenced dll is loaded via node_libraries (but with the consequent interpretation of that assembly as ZT nodes).

That’s a possibility, but by design I would wish the referenced library to remain agnostic to which APIs are built on top of it and their particular decorators, including Dynamo and others… :wink:

heres a thought:

how does your nodeModel reference the core library? If it only indirectly references it through the VM (ie you make a function call to it using a string name) then the .net runtime does not know to load your dll as a dependency of the nodeModel dll.

try to force it by using the function directly in your AST (not via string lookup) or try adding some hidden function to your library which simply references some types in the other assembly.

Uuuuh, that makes a lot of sense, I am going to give it a try, I’ll keep you posted.

Thanks!

did you ever get a chance to test this, there was some comments at the workshop that it didn’t help :frowning: