-
Notifications
You must be signed in to change notification settings - Fork 763
Closed
Description
Environment
- Pythonnet version: 3.0.3
- Python version: 3.11.9
- Operating System: 10.0.19045
- .NET Runtime: 8.0.301
Details
I compiled the following code to CalcTest.dll
with target framework netstandard2.0:
namespace CalcTest
{
public static class Calculator
{
public static int Add(int a, int b)
{
return a + b;
}
}
}
Then I tried importing the class Calculator
from Python:
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parent / "DLLs"))
import clr
clr.AddReference("CalcTest")
from CalcTest import Calculator
and I obtained the following error:
ImportError: cannot import name 'Calculator' from 'CalcTest' (unknown location)
Following the tutorial How To Call A Dynamic Library I changed the namespace in C# to CalcTestNS
, recompiled the project and updated the import in Python:
from CalcTestNS import Calculator
and it worked.
In the tutorial it is not mentioned that the namespace and the assembly cannot have the same name. It would be a great time-saver to document this.
Metadata
Metadata
Assignees
Labels
No labels