Coded workflow failed to invoke activity in my custom nupkg

Hey everyone!

I am trying to invoke a CodedWorkflow (Custom.cs) packaged in a nupkg (Custom.nupkg).
I can successfully invoke it as an Activity in the Main.xaml workflow, but it fails in the Main.cs workflow.
The following error occurs for the coded workflow:

Message: Object reference not set to an instance of an object.

Exception Type: System.NullReferenceException

System.NullReferenceException: Object reference not set to an instance of an object.   at System.Activities.WorkflowApplication.Invoke(Activity activity, IDictionary`2 inputs, WorkflowInstanceExtensionManager extensions, TimeSpan timeout)
   at System.Activities.WorkflowInvoker.Invoke(Activity workflow, TimeSpan timeout, WorkflowInstanceExtensionManager extensions)
......
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

The related files are as follow:

Custom.cs in nupkg

// import ...
namespace Custom
{
    public class Custom : CodedWorkflow
    {
        [Workflow]
        public void Execute()
        {
            uiAutomation.Open(ObjectRepository.Descriptors.MyApp.MyScreen);
            Log("This is a custom activity in Custom.nupkg.");
        }
    }
}

Main.xaml, it works.
image

Main.cs, it failed.

// import ...
namespace Main
{
    public class Main : CodedWorkflow
    {
        [Workflow]
        public void Execute()
        {            
            WorkflowInvoker.Invoke(new CustomActivity());
        }
    }
}

I have read the official documentation for creating custom activities, but I can’t proceed because Visual Studio is not available to my team, and services like uiAutomation and system are required for my custom activity.

Actually, I just want to invoke the coded workflow Custom.cs (in the nupkg) in Main.cs. I would be grateful if anyone could help me.

Could you please send me the complete project files, I will debug for you

See below. Many thanks.
demo_for_invoke_activities_in_nupkg.zip (63.1 KB)

1 Like