Grashopper document open inside wpf application

Hello everyone,

I’m integrating Rhino.Inside into a .NET 8 WPF application to run and visualize Grasshopper simulations (mainly KUKA PRC robotic simulations).
Rhino and Grasshopper start fine, and I can load .gh files through automation — for example:

dynamic gh = RhinoApp.GetPlugInObject("Grasshopper");
if (gh == null)
{
    RhinoApp.RunScript("_Grasshopper", false);
    gh = RhinoApp.GetPlugInObject("Grasshopper");
}

gh.OpenDocument(path);

The file opens successfully (I can see the geometry in the embedded Rhino viewport), but the loaded document never appears in Grasshopper.Instances.DocumentServer — the event
Instances.DocumentServer.DocumentAdded is never fired, and Instances.DocumentServer.Documents remains empty.


I also tried to start Grasshopper explicitly in headless mode:

var pluginObject = Rhino.RhinoApp.GetPlugInObject("Grasshopper") as Grasshopper.Plugin.GH_RhinoScriptInterface;
pluginObject.RunHeadless();

However, pluginObject is always null, even after confirming that Grasshopper is loaded.


If I try to open the document via Grasshopper.IO.OpenDocument, I get an error message saying that it can’t find definitions like
Folders.ComponentFolders or GH_ComponentServer.AddAssemblyFolder, which suggests that it might be initializing a different or incomplete instance of Grasshopper.


Environment:


Has anyone successfully accessed the Grasshopper document programmatically after loading it like this?
Or is there a proper way to ensure that the document opened through automation is attached to the same DocumentServer instance as Instances?

Any help or working example would be very appreciated!