Is can possibile integrate RF on C# code?

In order to control the various RPAs created, I would like to be able to integrate RF into C# code.
Is this possible?
With python.NET is possibile integrate python on c# but when I run the .robot files the result is this:

[ ERROR ] Error in file 'D:\Development\Project\RPAManage\bin\Debug\net7.0-windows\python\robots\test.robot' on line 2: Importing library 'RPA.Windows' failed: OSError: [WinError -2147417850] Cannot change thread mode after setting it
Traceback (most recent call last):
  File "c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\RPA\Windows\__init__.py", line 7, in <module>
    from RPA.core.windows import WindowsElementsMixin
  File "c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\RPA\core\windows\__init__.py", line 5, in <module>
    from .action import ActionMethods
  File "c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\RPA\core\windows\action.py", line 5, in <module>
    from RPA.core.windows.context import ActionNotPossible, WindowsContext
  File "c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\RPA\core\windows\context.py", line 8, in <module>
    import uiautomation as auto
  File "c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\uiautomation\__init__.py", line 4, in <module>
    from .uiautomation import *
  File "c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\uiautomation\uiautomation.py", line 23, in <module>
    import comtypes  # need 'pip install comtypes'
    ^^^^^^^^^^^^^^^
  File "c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\comtypes\__init__.py", line 232, in <module>
    CoInitializeEx()
  File "c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\comtypes\__init__.py", line 223, in CoInitializeEx
    _ole32.CoInitializeEx(None, flags)
  File "_ctypes/callproc.c", line 1000, in GetResult
PYTHONPATH:
  c:\users\d\appdata\local\programs\python\python311\python311.zip
  c:\users\d\appdata\local\programs\python\python311\DLLs
  c:\users\d\appdata\local\programs\python\python311\Lib
  D:\Development\Project\RPAManage\bin\Debug\net7.0-windows
  c:\users\d\appdata\local\programs\python\python311
  c:\users\d\appdata\local\programs\python\python311\Lib\site-packages
  c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\win32
  c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\win32\lib
  c:\users\d\appdata\local\programs\python\python311\Lib\site-packages\Pythonwin
  C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.0\
==============================================================================
OpenTest
==============================================================================
Apertura Broswer                                                      | FAIL |
No keyword with name 'Windows Run' found.
==============================================================================
Output:  D:\Development\Project\RPAManage\bin\Debug\net7.0-windows\output.xml
Log:     D:\Development\Project\RPAManage\bin\Debug\net7.0-windows\log.html
Report:  D:\Development\Project\RPAManage\bin\Debug\net7.0-windows\report.html

Hi Salvatore,

This appears to be your problem:

It looks like one of the prerequisite python modules is missing, I’ve never used python.net so I don’t know what the equivalent to pip is or if that module is even available?

Hopefully that helps,

Dave.

The problem is not the comtypes library unfortunately. Is installed and work well without pythonnet library.

I think the problem is here:
[WinError -2147417850] Cannot change thread mode after setting it

but I can’t solve it.

I fix this problem with not use python.net but run process directly on c# wtih ProcessStartInfo class.

1 Like