I am pretty new to UIPath and am wanting to use some custom C# code to process an Excel file that is rather large. I am trying to use the Inject .Net Code activity, but keep getting a generic Inject .NET Code: Dot net code failed exception.
UIPath is recognizing the class and methods contained in of the .dll file, but when it runs I keep getting a generic Inject .NET Code: Dot net code failed exception. I pared down the c# code to what amounts to a Hello World, and still get an error. Is there a particular .Net Framework that needs to be used, or anything?
The only code in the .dll is:
public class Class1
public static void testMethod()
Console.WriteLine("Hello World from the DLL!");
welcome in the UiPath Community.
I assume you mean the Invoke Code activity. This is the easiest way to execute C# code.
Try this in the Invoke Code activity:
Console.WriteLine("Hello World from the Inovke Code activity!");
If you want to use functions from DLLs, you can use this procedure.
Thanks for the reply.
I saw the invoke code activity and chose to give the inject .NET code a try instead so that I could debug the c# code separately.
UIPath recognizes the .dll file and the public static methods inside of it, but when it tries to invoke it, it just fails. I’ll try invoking the .dll from the invoke code activity as you outline in the linked tutorial and see what happens.
I have never used this activity before. This activity “Injects .NET code into the main UI thread of the target application. Intended for usage with .NET UI applications that do not expose traditional automation technologies or cannot be correctly targeted by traditional means”, as the documentation says. In my opinion really only for special use cases to apply.
I changed your code a little bit:
public class Class1
public static object testMethod()
return "Hello World from the DLL!";
It delivers now an object back, because I assume a console output will not really work in this context. As target I use a tiny dotNET Windows Forms application and it works as expected.
I recommend you to use the Invoke Code Activity instead of Inject dotNET DLL code into a running application. Running DLL code is much easier with Invoke Code activity. Unless you want to automate an UI that can’t be automated on another way.
Great info, I read the documentation, but did not realize it would only work if the program had a UI, I was actually going to try a Windows form app as a test today as well. I don’t need any UI functionality, so I will go with your suggestion of invoking the .dll from the invoke code activity. Thankyou much!!!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.