Fail to load assemblies created by C++/CLI

Hello Dynamo community

I tried to load the components created by C++/CLI to Dynamo project. The project is written in C# to read some nodes and create the trusses out from the nodes.

I implemented in C++ some native operations to compute the truss internal force, load on node, etc. I used CLI to export that C++ components to C#. I reference the CLI project in C# project in order to use the wrapped native classes. However, when I used the CLI components in C#, for example

    private Point m_dyn_point;

    private Node(Point point)
    {
        m_dyn_point = point;
        m_node = new OOFEMcli.Node(0, m_dyn_point.X, m_dyn_point.Y, m_dyn_point.Z); // create new instance of CLI class
    }

That gives me an error when I launch the plugin in DynamoSandBox. It says that the CLI assemblies failed to load

Can anyone suggest a possible way to overcome this? Thank you very much.

are your c++ binaries compiled to x64 or x86? Is this an issue with the C++CLI - have not used this before.

I compiled the C++ to x86. However, I compiled DynamoSandbox using “Any CPU” mode. So I think it has no problem to load the assemblies

Furthermore, removing the line
m_node = new OOFEMcli.Node(0, m_dyn_point.X, m_dyn_point.Y, m_dyn_point.Z); // create new instance of CLI class

make the plugin works normally.

I used Costura.Fody to wrap all assemblies in one DLL. Now Dynamo can load the plugin, but another error came up

Probably, the error is because Dynamo cannot load lower native “unmanaged” (but it’s managed by CLI). That’s strange because I tried to load the same CLI in other project in C# (not related with Dynamo) and it’s working just fine.

I don’t think that’s the case with unmanaged assemblies - compile them to x64.

Thanks. Compiling to x64 resolved the issue. Do you know what is the reason?

native binaries are not the same as managed ones and cannot be built for anyCPU, you must load the correct version depending on the CPU type.

Now I got it. Thanks again.