How to load Dynamo assemblies in Reviti api?

Hi, I want to run dynamo description with this code.

string path = @".dyn path";

IDictionary<string, string> journalData = new Dictionary<string, string>
{
    { Dynamo.Applications.JournalKeys.ShowUiKey, false.ToString() }, // don't show DynamoUI at runtime
    { Dynamo.Applications.JournalKeys.AutomationModeKey, true.ToString() }, //run journal automatically
    { Dynamo.Applications.JournalKeys.DynPathKey, "" }, //run node at this file path
    { Dynamo.Applications.JournalKeys.DynPathExecuteKey, true.ToString() }, // The journal file can specify if the Dynamo workspace opened from DynPathKey will be executed or not. If we are in automation mode the workspace will be executed regardless of this key.
    { Dynamo.Applications.JournalKeys.ForceManualRunKey, false.ToString() }, // don't run in manual mode
    { Dynamo.Applications.JournalKeys.ModelShutDownKey, true.ToString() },
    { Dynamo.Applications.JournalKeys.ModelNodesInfo, false.ToString() }
};


DynamoRevitCommandData dynamoRevitCommandData = new DynamoRevitCommandData();
dynamoRevitCommandData.Application = uiApp;
dynamoRevitCommandData.JournalData = journalData;

DynamoRevit dynamoRevit = new DynamoRevit();
Result externalCommandResult = dynamoRevit.ExecuteCommand(dynamoRevitCommandData);

DynamoRevit.RevitDynamoModel.OpenFileFromPath(path, true);

List<NodeModel> nodeModels = DynamoRevit.RevitDynamoModel.CurrentWorkspace.Nodes.ToList();
List<NodeModel> isInputNodes = new List<NodeModel>();
List<NodeModel> isOutputNodes = new List<NodeModel>();

foreach (NodeModel node in nodeModels)
{
    if (node.IsSetAsInput) isInputNodes.Add(node);
    if (node.IsSetAsOutput) isOutputNodes.Add(node);
}

After running Dynamo once, the code works without any problems.

However, if I run the next code without running Dynamo, I get this error.
(In Herer : dynamoRevit.ExecuteCommand(dynamoRevitCommandData):wink:

I think I should load assemblies about Dynamo before run that code.
How can I do?

I would highlight that there has been discussions about how to load dynamo via this method on the forum that may be able to guide you.

I will highlight that you probably need to look at your order of execution, because i think the “DynamoRevit()” item needs to be straight after the string path.

Also have a look at John Piersons example of this from here(Relay/src/Methods/DynamoMethods.cs at master · johnpierson/Relay · GitHub), he had some issues and changed the way the method works.

This is a link to the original version and as you can see the order is different compared to how you have done it - Relay/src2/Methods/DynamoMethods.cs at 27f3fa89cacc244406705d8e879220cd0c0dca73 · johnpierson/Relay · GitHub