I've been using Pythonnet for quite some time but always against .NET Framework 4.* With the recent release of .NET 5.0 I wanted to migrate my projects but I could not make it work for non-Framework versions (e.g. .NET Core 2.0, .NET Core 3.0, .NET 5.0)
Here is a very simple test I ran with .NET Framework 4.5:
namespace TestNet
{
public class Dummy
{
private string _name;
public Dummy(string name)
{
_name = name;
}
public string Hello(string name)
{
return $"Hello {name}, my name is {_name}";
}
}
}
This produces TestNet.dll then I run the following Python code:
>>> import clr
>>> clr.AddReference("TestNet")
<System.Reflection.RuntimeAssembly object at 0x000001899ACFABB0>
>>> from TestNet import Dummy
>>> d = Dummy("Bob")
>>> d.Hello("John")
'Hello John, my name is Bob'
So everything works fine.
Now, the exact same C# code but targeting .NET Core or .NET 5.0 will give me:
>>> import clr
>>> clr.AddReference("TestNet")
<System.Reflection.RuntimeAssembly object at 0x00000122AF0DABB0>
>>> from TestNet import Dummy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'TestNet'
My understanding is they are using CoreClr and not CLR and from Pythonnet website (https://pythonnet.github.io/):
Python.NET (pythonnet) is a package that gives Python programmers nearly seamless integration with the .NET 4.0+ Common Language Runtime (CLR)
Does anyone know if CoreClr is supported?
Thanks!
Env: Python 3.8/Windows 10
Support for .NET 5 has been added to Python.NET although it's not released yet.
See here for an example
Pythonnet dotnet core 'No module named'