Call the library directly with UiPath

Call the library directly with UiPath

With UiPath, it has become easier to add custom libraries from Orchestrator, UiPath Go, etc., but from the demonstration experiment stage, it is difficult to install Orchestrator or register your own library in UiPath Go. In the first place, it can be difficult to register even the network whitelist.

In this post, I'll show you how to call your own custom library (DLL) directly, not from .nuget.

Trigger for development

It's commonplace these days, but in the old days, to create a custom library with UiPath, I had no choice but to create a DLL with Visual Studio and nuget the DLL with Nuget Explorer etc.

Even when debugging with UiPath, there is no Immediate Panel, or even at the moment debugging Com and lambda expressions Could not be analyzed.

Promise (Disclaimer)

This article was created based on the information as of June 2020. The content of the article is my personal opinion, not the official opinion of the organization to which I belong.

Usage image

For the usage image, the DLL of the custom library is stored in a specific folder (for example, under the project), and I would like to call it from a DLL file, much like invoking an xaml file.

image.png

Custom library

The DLL that can be used in the sample is prepared here. https://github.com/takusonix/UiPathCustomLibrary/raw/master/UiPathCustomLibrary/bin/Release/UiPathCustomLibrary.dll

The source content is here.

using System.Windows;

namespace UiPathCustomLibrary
{
    public static class TestClass
    {
        public static void Test1()
        {
            MessageBox.Show("Hello World");
        }
        public static void Test2(string message)
        {
            MessageBox.Show(message);
        }

        public static int Test3(int a, int b)
        {
            return a + b;
        }
    }
}

You may prepare your own without using the sample DLL.

UiPath project structure

The UiPath project structure looks like this. The custom library sample (UiPathCustomLibrary.dll) is stored directly under the project. image.png

UiPath implementation

1. Creating assembly variables

Create a variable called ʻasm` in UiPath. image.png

2. Change type

Select Browse for Types ... as the asm type. image.png

3. Model name

Enter System.Reflection.Assembly for the Type Name and select Assembly. image.png

4. Add Assign

Add an Assign activity and set ʻasm` on the left side. image.png

5. Set the value of Assign

Set the following values on the right side of Assign.

Assembly.LoadFile( _
    Path.Combine( _
	    Environment.CurrentDirectory, _
		"UiPathCustomLibrary.dll" _
	) _
)

image.png

*** You have now loaded the DLL. *** ***

6. Add variable

Add a variable for the method to execute

--Namespace (usingName) --Class Name --MethodName

image.png

7. Set the value of the variable

Set the values for each variable.

image.png

8. Add execution result variables

Add the variable resultObj to set the execution result and change the variable type to ʻObject`. image.png

9. Add Assign

Add an Assign that sets the execution and execution result. image.png

10. Call the process

Set the value of resultObj to the following value

asm _
    .GetType( usingName + "." + className ) _
    .GetMethod(methodName) _
	.Invoke(Nothing, Nothing)

image.png

Run UiPath

When executed, the Hello World message will be displayed. (If the message box is not displayed in the foreground, please select the unnamed task of UiPath Robot from the taskbar as shown in the image.) image.png

At the end

In this post, I've only called the method. The Test2 and Test3 methods provided in the sample custom library, argument settings, and execution result acquisition will be posted separately.

If you like, please use LGTM.

Recommended Posts