Problems when dynamically invoke an activity in Invoke Code

in my workflow, I wanna dynamically create a WPF window, with several buttons on it. When I click the buttons, it will invoke a sub-process. The sub-processes are all located in a folder in my project. I’ve done it by writing some codes in an Invoke Code activity. Here is my code. The sub-process can be invoked, but if there’re Invoke Workflow File activities in the sub-process, a runtime error, Object reference not set to an instance of an object, would be thrown when executing the Invoke Workflow File. Any ideas on why would this happen? What am I missing? Thanks!

  	AddHandler btn.Click, Sub(sender2, e2)
  		Dim btnEvent As System.Windows.Controls.Button = CType(sender2, System.Windows.Controls.Button)
  		Dim processName As String = btnEvent.Tag.ToString
  		Dim act As Activity = ActivityXamlServices.Load("General\" + processName + "\Main.xaml")
  		Dim inputs As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
  		inputs.Add("BasePath", Path.Combine(Environment.CurrentDirectory,"General",processName))
  		WorkflowInvoker.Invoke(act, inputs)
  	End Sub

I’m not pretty sure but did you check following?

Suppose your Main.xaml project is in
C:\UiPath\WorkflowMain and you call InvokeCode activity from within Main.xaml

And also suppose your dynamically trigerred workflows from within InvokeCode activity reside in

in that case WorkflowMain project may look for dynamic sub workflows within C:\UiPath\WorkflowMain directory like C:\UiPath\WorkflowMain\DynamicWorkflows

can you use some log activities to log the locations?

Otherwise if there is not anything intentionally blocked or mandatory in uirobot WorkflowHost then this should work as expected. If there are some limitations then perhaps that would be good to consider it with some UiPath’s development team.

For example uirobot WorkflowHost may expect some mandatory internal variables that prevent simply calling WorkflowInvoker.Invoke method without these variables set but, anyway uirobot WorkflowHost is a blackbox at the moment and we cannot know how it triggers a xaml file, with which parameters e.t.c.


Hi, I think it has nothing to do with the location. My Main.xaml, say, is in C:\UiPath\SupFolder, and the sub process is in C:\UiPath\SupFolder\SubFolder.
The sub process can be successfully invoked, but when it executes the Invoke Workflow File activity inside the process, the error is thrown. Same situation occurs when there’s GetOrchestratorCredential in the sub process.

What is the uirobot WorkflowHost? Is it an object exsits in the workflow application? I can’t find something like this. Thanks!

Hi Jo,

I thought the same actually but was just an idea, checking the locations don’t cause anny issue.

WorkflowHost is the main class that manages Windows Workflow Foundation processes and UiPath is built on Windows Workflow Foundation. Actually The Robot is nothing but a Windows process and the name of this process is uirobot thus uirobot is running on top of Windows Workflow Foundation then we can call uirobot process as a WorkflowHost.

Implementation of a WorkflowHost may differ for every project with lots of assumptions. According to your error, object reference not set for an object message is very common in Microsoft .NET projects which means some code part of the process is trying to use some variable which is not set to any class/struct instance, simply trying to use empty object actually. This makes me think that uirobot requires some variables to be set before invoking a workflow with WorkflowInvoker.Invoke method.

If this is the case then we cannot know actually what is happening inside the uirobot (WorkflowHost) because uirobot is black-box for us at the moment unless UiPath opens it’s source for the sake of humanity :slight_smile:

I’m sure you may have reasons to follow this way, I mean invoking workflow proces from within InvokeCode activity but, I’d try to find another ways to achieve the functionality.

e.g. I’m sure this btn object is a button on a visual form. If I were you, I’d use monitor events to monitor this button then use regular InvokeWorkflow activity within Montor Events activity handler, to invoke the sub workflows dynamically. I didn’t test it but I think this approach would work and would cause less headache, at least you wouldn’t need to take care about thes WorkflowHost things with that way :slight_smile:


Aha, I see. And what I’ve done now is to use a FileChange Event Monitor. It’s a little tricky but can solve my problem.:grinning:

1 Like

Perfect :slight_smile:

Working solution is the best solution :smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.