# Errors when invoking coded workflows in libraries

**URL:** <https://forum.uipath.com/t/errors-when-invoking-coded-workflows-in-libraries/767897>\
**Category:** Activities\
**Tags:** invoke-code, code, coded, coded-automation, coded-workflow, question, studio\
**Created:** [9월 19, 2024, 4:05오전 UTC](https://forum.uipath.com/t/errors-when-invoking-coded-workflows-in-libraries/767897 "2024-09-19T04:05:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Timothy\_Morris](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/timothy_morris/32/490255_2.png) [@Timothy\_Morris](https://forum.uipath.com/u/Timothy_Morris)\
**Post date:** [9월 19, 2024, 4:05오전 UTC](https://forum.uipath.com/t/errors-when-invoking-coded-workflows-in-libraries/767897/1 "2024-09-19T04:05:34Z")

</div>

Hi all,

[Example.zip](https://forum.uipath.com/uploads/short-url/icszXzsVnqR3m13lSyzl2nDg8Sf.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.

```auto
using UiPath.CodedWorkflows;

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

```

```auto
using UiPath.CodedWorkflows;

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

```

 ![The image displays an error log indicating a `System.NullReferenceException` in a UiPath CodedWorkflow due to an object not being set to an instance, with a detailed stack trace from various functions and files. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/9/1/f/91f82f26e98805b1a3ad91021f190b714e803bbb.png)

Am I executing the workflow correctly? This [UiPath Documentation (Invoking coded automations using libraries)](https://docs.uipath.com/studio/standalone/2024.10/user-guide/invoking-coded-automations-using-libraries) says a coded workflow should be invoked like this but the coded workflow is a class, not a method.

```auto
myFavoriteLibrary.<WorkflowFromThatLibrary>()

```

The only way I can make it work is:

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

```

I appreciate the help.

Thanks,

Tim

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [9월 19, 2024, 4:14오전 UTC](https://forum.uipath.com/t/errors-when-invoking-coded-workflows-in-libraries/767897/2 "2024-09-19T04:14:48Z")

</div>

@Timothy_Morris

FYI.please check this

> [@Coded Workflow, error when calling a workflow in a library from an external project](https://forum.uipath.com/t/coded-workflow-error-when-calling-a-workflow-in-a-library-from-an-external-project/669590/11):
>
> @fjartacho Found a workaound to execute from library directly please try the saem…I tried and it is working as expected So instead of using RunWorkflow…I am Explicitly initializing the CodedWorkflow I Need and then calling execute…this way it is workign from the project as well… Hope this helps cheers

Log does create an issue

Cheers

---

<div class="post-metadata">

**Author:** ![Timothy\_Morris](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/timothy_morris/32/490255_2.png) [@Timothy\_Morris](https://forum.uipath.com/u/Timothy_Morris)\
**Post date:** [9월 19, 2024, 5:45오전 UTC](https://forum.uipath.com/t/errors-when-invoking-coded-workflows-in-libraries/767897/3 "2024-09-19T05:45:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [9월 22, 2024, 5:45오전 UTC](https://forum.uipath.com/t/errors-when-invoking-coded-workflows-in-libraries/767897/4 "2024-09-22T05:45:53Z")

</div>

9월 22, 2024, 5:45오전 UTC에 닫힘

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