Errors when invoking coded workflows in libraries

Hi all,

Example.zip (190.4 KB)

Can someone please help me understand why I am getting this NullReferenceException when invoking this coded workflow (that is in a published library) from a coded workflow in a process?

I believe it is because the CodedWorkflow services (including the logging service) are not being initialised but I can’t work out how to initialise them.

using UiPath.CodedWorkflows;

namespace MyLibrary
{
    public class MyCodedWorkflow : CodedWorkflow
    {
        [Workflow]
        public void Execute()
        {
            Log("Running MyCodedWorkflow!");
        }
    }
}
using UiPath.CodedWorkflows;

namespace MyProcess
{
    public class MyCodedWorkflowInProcess : CodedWorkflow
    {
        [Workflow]
        public void Execute()
        {
            var workflow = new MyLibrary.MyCodedWorkflow();
            workflow.Execute();
        }
    }
}

Am I executing the workflow correctly? This UiPath Documentation (Invoking coded automations using libraries) says a coded workflow should be invoked like this but the coded workflow is a class, not a method.

myFavoriteLibrary.<WorkflowFromThatLibrary>()

The only way I can make it work is:

var workflow = new MyLibrary.MyCodedWorkflow();
            workflow. Execute();

I appreciate the help.

Thanks,

Tim

@Timothy_Morris

FYI.please check this

Log does create an issue

Cheers

Hi Anil,

I had read that thread a few times today but unfortunately it doesn’t provide a solution. Console.WriteLine is not a substitute for the Log method which logs to Orchestrator.

I have found the solution though.

When importing a library, a new member is added to CodedWorkflow and this member is in lower camel case. This is a service that invokes the workflows in the library and is available to the coded worklows that inherit from the CodedWorkflow class.

In my example above, it would be “myLibrary”. To invoke a workflow, it’d be myLibrary.MyCodedWorkflow().

This is the proper way to invoke coded workflows that have been imported via a library and ensures services are initialised. This allows the Log method to be used.

I really wish UiPath documented this better and highlighted that the service is in lower camel case. A downloadable example would have been good too.

Regards,

TIm

1 Like

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