Custom library (Classes and methods)

Hello, I’m trying to add a Custom Class so I can use custom methods in UiPath.

using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace CSharpLibrary
{
	public class DataManipulation
	{
		public DataManipulation()
        {

        }

		public string GetStringFromDictionary(Dictionary<string, object> dict, string key, string name)
		{
			if (name == null || name == String.Empty)
			{
				name = "Config";
			}
			try
			{
				return dict[key].ToString();
			}
			catch (KeyNotFoundException knfE)
			{
				throw new Exception("The Key <" + key + "> was not found in the dictionary: <" + name + ">. " + knfE.Message);
			}
			catch (ArgumentException argE)
			{
				throw new Exception("The Key <" + key + "> was not found in the dictionary: <" + name + ">. " + argE.Message);
			}
			catch (Exception E)
			{
				throw new Exception("Unexpected error while searching the key <" + key + "> in the dictionary: <" + name + ">. " + E.Message);
			}
		}
	}
}

I tried to follow the steps in this post:

And I tried other different things, like changing the target framework to 4.8 or different ones and naming the Id of the package so it ends in “.Activities”.

The most I achieved was being able to create a variable in UiPath of the mentioned class:


But I can’t manage to access the method of the class.

What am I doing wrong? Can someone provide a “2022 tested guide” on how to achieve that?

1 Like

Hey @Palayn

In the variables panel default value just pass the below…

new DataManipulation()

You have declared your custom class type object as variables but not initializing it which is causing this issue.

Hope this helps

Thanks
#nK

Sorry but that should only fail in runtime. I can’t access the method in the studio. Nevertheless, I did it and it didn’t work either.

1 Like

Oh yes, you are right

Hey @Palayn

Could you please show the library project structure once pls ?

Thanks
#nK

Here it is:
image

I uploaded the project, the pkg and the vs proj if you also want to check. Thanks in advance.
BindCSharpLibrary.1.0.0.nupkg (3.7 KB)
BindCSharpLibrary.zip (35.3 KB)
TestProcess.zip (56.6 KB)

Hi,

In my environment, your project seems no problem as the following.

img20220216-1

For now, can you try to delete files in %USERPROFILE%\.nuget\packages\bindcsharplibrary?

Regards,

Thanks! I did what you said and now it indeed appears, however, it shows me an error: “DataManipulation is not defined”


Any clues on why that is happening?

Also, could you use the activity yourself? You should be able to test it with a dictionary(of string, object), and two strings.

Hi,
Can you try to check if BindCSharpibrary exists in Imports panel?

Or call BindCSharplLibrary.DataManipulation.

Regards,

Hi,

FYI, as your custom library is compiled for NetStandard2.0, it might be trouble in Windows-Legacy compatible project.
So you need to use this custom library in Windows (.net5) compatible OR re-compile it as net461 target.

The following is a sample in windows(net5) compatible. It works well in my environment.

Sample20220216-2CsNet5.zip (2.6 KB)

Regards,

Thank you very much for everything! And for the advice!

At the end I could use it, I’m having a little trouble when adding the reference, as it seems at the beginning that it is not recognized (as I showed in the error message), and also in the imports section you mentioned for some reason the BindCSharpLibrary appeared twice. I had to delete variables, uninstall the package, delete the imports, and try again and it worked.

1 Like

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