Relative path (referencing a DLL)

Hi, I believe this has been discussed elsewhere, but is there a chance to use a relative path when referencing a DLL in C#? I want to put a DLL in the same folder as the gh definition, and make it discoverable.

Thanks!

You should be able to use AssemblyLoadContext.Resolving to figure out at runtime where to load an assembly from that could not be loaded.

1 Like

We used to have to something similar some of our assemblies:

image

1 Like

This seems like an awful lot more effort than having our scripting system handle references for DLLs in the same directory as the definition. Maybe @eirannejad already has something for this.

@mikity_kogekoge I am improving the package and dll reference system in Rhino WIP right now. The relative paths work in normal scripts but not scripts inside of Grasshopper. A workaround is to load the dll manually somewhere in the definition.

Thanks!

Found a workaround. Just load the DLL in a separate Python component. Then connect a dummy output to a dummy input of the target C# component. That way, the DLL is discoverable in the C# component.

import os
import clr

a=os.path.join(os.path.dirname(ghenv.Component.OnPingDocument().FilePath),"KingOfMonsters.dll")

clr.AddReference(a)
2 Likes