# Adding SAP GUI scripting dll to custom activity

**URL:** <https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952>\
**Category:** Activities\
**Tags:** sap-gui-scripting, sapgui, dll, custom-activity, studio, sap, activities\
**Created:** [June 6, 2024, 8:35am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952 "2024-06-06T08:35:13Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilia\_Elagin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ilia_elagin/32/426450_2.png) [@Ilia\_Elagin](https://forum.uipath.com/u/Ilia_Elagin)\
**Post date:** [June 6, 2024, 8:35am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/1 "2024-06-06T08:35:13Z")

</div>

Greetings!

I’m trying to write a custom activity using Visual Studio C# and need to use sapfewse.dll there. While the package builds without any problems, UiPath returns an error, when I try to add a variable to any of the Activities. The library does contain “GuiSession” however. What could be the issue causing this error?

 ![Screenshot 2024-06-06 102953](https://global.discourse-cdn.com/uipath/original/4X/0/2/5/025a2fd7f89682d5ba1d014961a2a1872c2ddf59.png)

Thank you

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [June 6, 2024, 11:33am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/2 "2024-06-06T11:33:52Z")

</div>

@Ilia_Elagin,

Check if you could import the sapfewse dll in your workflow using Imports panel in Studio.

Thanks,  
Ashok 🙂

---

<div class="post-metadata">

**Author:** ![Ilia\_Elagin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ilia_elagin/32/426450_2.png) [@Ilia\_Elagin](https://forum.uipath.com/u/Ilia_Elagin)\
**Post date:** [June 7, 2024, 8:50am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/3 "2024-06-07T08:50:00Z")

</div>

@ashokkarale ,

Thank you for your answer!  
The package appears to be imported and it shows up in the Imports panel.  
 ![Screenshot 2024-06-07 104832](https://global.discourse-cdn.com/uipath/original/4X/f/d/d/fdd3bd41660a827348b8c2f3f39c815c24b55f30.png)

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [June 7, 2024, 9:01am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/4 "2024-06-07T09:01:56Z")

</div>

@Ilia_Elagin,

Ok. What’s the variable datatype you have declared?

Thanks,  
Ashok 🙂

---

<div class="post-metadata">

**Author:** ![Sergey\_Rysev](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sergey_rysev/32/428265_2.png) [@Sergey\_Rysev](https://forum.uipath.com/u/Sergey_Rysev)\
**Post date:** [June 7, 2024, 1:56pm UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/5 "2024-06-07T13:56:22Z")

</div>

@ashokkarale ,  
I am also part of Ilias team and try to answer 🙂  
in the c# code we have something like this:

sapfewse.GuiSession GuiSession = …

our reference to the libraries in the \*.csproj looks like this:

 ..\libs\sapfewse.dll True ..\libs\saprotwr.net.dll True

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [June 7, 2024, 2:13pm UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/6 "2024-06-07T14:13:25Z")

</div>

@Sergey_Rysev,

Ok, so how you are creating instance of sapfewse.GuiSession and passing it?

---

<div class="post-metadata">

**Author:** ![Sergey\_Rysev](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sergey_rysev/32/428265_2.png) [@Sergey\_Rysev](https://forum.uipath.com/u/Sergey_Rysev)\
**Post date:** [June 7, 2024, 2:35pm UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/7 "2024-06-07T14:35:48Z")

</div>

@ashokkarale  
we are trying to port the old UiPrime library to the the version of UiPath.  
we took the code from here: [GitHub - uiprimeteam/UiPrimePackage](https://github.com/uiprimeteam/UiPrimePackage/)  
and we assume the error happens either here: [UiPrimePackage/UiPrime.SAP/Activities/\_Common.cs at 91def66dfd3b10325a973f9610a2d14211844691 · uiprimeteam/UiPrimePackage · GitHub](https://github.com/uiprimeteam/UiPrimePackage/blob/91def66dfd3b10325a973f9610a2d14211844691/UiPrime.SAP/Activities/_Common.cs)  
or here: [UiPrimePackage/UiPrime.SAP/Activities/\_GuiSession.cs at 91def66dfd3b10325a973f9610a2d14211844691 · uiprimeteam/UiPrimePackage · GitHub](https://github.com/uiprimeteam/UiPrimePackage/blob/91def66dfd3b10325a973f9610a2d14211844691/UiPrime.SAP/Activities/_GuiSession.cs#L144)

---

<div class="post-metadata">

**Author:** ![LevKushnir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/levkushnir/32/124465_2.png) [@LevKushnir](https://forum.uipath.com/u/LevKushnir)\
**Post date:** [June 14, 2024, 9:26am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/8 "2024-06-14T09:26:44Z")

</div>

HI @StefanSchnell

Hope you are doing well. Could I kindly ask your for an advice?

You have a plenty of expertise in this area

Thanks a lot, Lev

---

<div class="post-metadata">

**Author:** ![LevKushnir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/levkushnir/32/124465_2.png) [@LevKushnir](https://forum.uipath.com/u/LevKushnir)\
**Post date:** [June 14, 2024, 9:28am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/9 "2024-06-14T09:28:15Z")

</div>

HI @Ilia_Elagin

Have you seen this solution?

> [@UIPath Invoke VBScript](https://forum.uipath.com/t/uipath-invoke-vbscript/208471/3):
>
> Hello @Johann, in my opinion it is not necessary to transfer the GUISession object to the VBScript directly. You know the session object in your calling program. With the property ID you can get the full ID of the session as string, e.g. like this: /app/con[0]/ses[1] Dismantle this string to get the connection number, in this example 0, and the session number, in this example 1. Now you can [transfer this numbers to your VBScript and use it like I described here](https://forum.uipath.com/t/tip-sap-gui-scripting-development-scenarios-in-the-context-of-uipath). A tiny hint: It is not possib…

or this discussion

> [@How to access SAP GUI objects' methods and properties](https://forum.uipath.com/t/how-to-access-sap-gui-objects-methods-and-properties/329649):
>
> Hello, I’m trying to get access to various properties and methods of SAP elements ([like this](https://help.sap.com/viewer/b47d018c3b9b45e897faf66a6c0885a8/760.03/en-US/ce1d9e64355d49568e5def5271aea2db.html)) using UiPath Studio. I can spy SAP elements via studio but they are UiElement type. And I can only access UiElement class methods and properties. I’ve tried using the invoke code, but cannot make it work. Although similar code works fine in VBA or VBS, I cannot make it work in the UiPath. The [VB.net](http://VB.net) code is following, this is just a simple connector to an existing SAP instance: Dim SapGuiAuto As Ob…

Best regards, Lev

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [June 14, 2024, 9:34am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/10 "2024-06-14T09:34:53Z")

</div>

@Ilia_Elagin  
can you check the presence of the sapfewse.ocx at the machine?

possible paths:  
C:\Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx  
C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapfewse.ocx  
…

---

<div class="post-metadata">

**Author:** ![Ilia\_Elagin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ilia_elagin/32/426450_2.png) [@Ilia\_Elagin](https://forum.uipath.com/u/Ilia_Elagin)\
**Post date:** [June 18, 2024, 12:03pm UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/11 "2024-06-18T12:03:59Z")

</div>

Hello @ppr ,  
Thank you for your answer!  
Yes, we have this file on the machine, where we use our custom activity.

---

<div class="post-metadata">

**Author:** ![Ilia\_Elagin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ilia_elagin/32/426450_2.png) [@Ilia\_Elagin](https://forum.uipath.com/u/Ilia_Elagin)\
**Post date:** [June 19, 2024, 11:13am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/12 "2024-06-19T11:13:25Z")

</div>

Hello @LevKushnir  
Thank you for your answer!  
I went through both threads, but unfortunately couldn’t find the information that might help with our case. I have the assumption, that the issue might be with the library we are using, sapfewse.dll, being written with an older dotnet version, which is only supported in UiPath legacy projects.

---

<div class="post-metadata">

**Author:** ![Ilia\_Elagin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ilia_elagin/32/426450_2.png) [@Ilia\_Elagin](https://forum.uipath.com/u/Ilia_Elagin)\
**Post date:** [July 24, 2024, 7:34am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/13 "2024-07-24T07:34:30Z")

</div>

We finally could reach the solution. It was important to set properties “Copy Local” and “Embed Interop Types” of each relevant import to yes and no respectively. It was also necessary to add the following lines for each relevant import inside the `<Target Name="AddDlls"/>` in \*.Packaging Project:  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/2/4/5/24540ca038111484a4399628de18cf14a49b23f8.png)

---

<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:** [July 27, 2024, 7:34am UTC](https://forum.uipath.com/t/adding-sap-gui-scripting-dll-to-custom-activity/745952/14 "2024-07-27T07:34:50Z")

</div>

Closed on July 27, 2024, 7:34am UTC

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