'How to call public method in .NET5 dll from RapsberryPi using Python 3.9
I have Win10 (64 bit) VS2019 C# .NET5 project. This project contains public method named "Add(int a, int b)" in public class "Calculate" in namespace "CsharpDll". Built end result is "CsharpDll.dll" file.
I am trying to call this "Add()" method from Raspberry Pi using RaspberryPi OS (32 bit) and Python 3.9. So far without success.
Note: "pythonnet" library does not support Python version 3.9. and installation will fail without attribute "--pre". Before running the Python code, I installed "pythonnet" library to Raspberry Pi using following command:
pip install --pre pythonnet
Here is the C# .NET5 sample I used:
using System;
namespace CsharpDll
{
public class Calculate
{
public int Add(int a, int b)
{
return a+b;
}
}
}
Here is the Python sample I used:
#!/usr/bin/env python
import clr
from CsharpDll import Calculate
# set path variables
clr.AddReference('/home/.../CsharpDll.dll')
# create object
myDll = Calculate()
print('C# returned value: ', myDll.Add(1,2))
Expected result: C# returned value: 3
Actual result was an error message:
File "/home/.../.local/lib/python3.9/site-packages/clr_loader/util/find.py", line 67, in find_libmono
raise RuntimeError("Could not find libmono")
RuntimeError: Could not find libmono
Question: Has anybody used .NET5 dll in Ruspberry Pi with Python 3.9, and have any ideas how to solve this issue?
Kindly Yours, Antti
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
