-
Notifications
You must be signed in to change notification settings - Fork 747
Implement CLR loading in pure Python #857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I tried the loader from your gist in #857 and it caused a hard crash on windows nano server w/ .net core 2.2 and miniconda. Originally posted by @spinwards in #612 (comment) |
I've tested it using docker with the mcr.microsoft.com/dotnet/core/sdk:2.2 image with both miniconda and a vanilla python install and a copy of Python.Runtime.dll that targets .net standard 2. In all cases when I call func(), python immediately crashes with a generic "Windows fatal exception: access violation". I had to modify the build somewhat to get it to run in VS2019, so it might be a problem on my end. |
I don't get this error, it works for me on both Linux and Windows up to the point that it complains about |
Sure, with the net40 target platform, but I am running this on nanoserver with .net core2. I need the ReflectionPolyfill class to adapt the DefineDynamicAssembly method for .net standard. If I remove the net40 target framework and build the resulting assembly gives me an access violation. |
Work is ongoing in https://github.com/filmor/clr-loader. I'm able to load up .NET Core (>=3 due to hostfxr changes) and get a callable object in Python for something that has the signature |
We are getting there, Mono is implemented as well now, I'll try to add .NET framework support tonight. |
.NET framework support as well as a simple interface are also implemented now. I will create a PR that drops |
Hello, I'm interested on the status of this ! Is there some way to use a dotnet core DLL with pythonnet right now ? And on Linux (both x86 and arm), how do we proceed, as we could install mono and/or MS dotnet core sdk: which one is needed ? How to import, AddReferences, use the assemblies ?
|
Hi, I also tried loading a .NET Core 2.0, 2.1 or 3.1 dll using pythonnet. It failed just like @kpoman 's attempt. So I dug a little deeper and it seems, without knowing any details, that pythonnet is loading "some" Runtime when you call So @filmor: Is there a way I can tell pythonnet to use another directory? Because I can build (rather publish) my dotnetcore application as self contained. So in my mind it would make sense to tell pythonnet to just use this directory where I have my application DLLs + the Runtime to load all of it. Here some print out where it shows that the System.Runtime 4.0.0.0 is loaded from my default installation and the attempt to load a different Runtime afterwards fails (of course)
|
This is much more complicated than you make it out to be :). The reason this works in the way it currently does is because of some magic with regard to how Windows deals with .NET DLLs. There is startup code in there that loads I have already started work on this, but don't expect anything usable before January. The loader as such already works (see https://github.com/filmor/clr-loader) for all dynamic .NET runtimes (Framework, Core, Mono), now I'm in the process of refactoring Python.NET to make use of this in #1015. |
Yeah I thought it might be. I'll check out your loader and look around. Maybe I can help out with something (doubtful but I'll try) |
Appreciate all your hard work and brains on this 🙂. What's the answer to the question about self-contained exe/dlls, will those be loadable under the new mechanism such that users won't need .net core 3 installed? Happy to raise a separate issue about it if it needs something different doing |
@mungojam Contributions to |
@filmor thanks for the pointer. I've just taken a look at the output from a simple self-contained build and it contains I reckon the easy way then with the existing code will be to set the I will give this a spin at some point to fully confirm. The only way I can see it could work automatically would be if the hostfxr loader would wait until at least one DLL was referenced so that it could go looking into the same folder as those DLLs, but that sounds complicated and not worth it. |
@lostmsu We can just rename 2.5 to 3.0. |
There's already 3.0 :-D |
A mild bump, what's the state of this issue? When would it be possible to load a .net core assembly? |
@hillin Development happens completely in the open. If you don't see any progress on this issue in form of comments or commits, then there is no progress. |
@filmor have you been working on this lately? What is the status? |
I've given this some thought, and now think this should ideally be a separate Python module to be published for pip, that the main repository should depend on. e.g. import hostfxr
hostfxr.init()
hostfxr.get_delegate() BTW, the linked notebook uses the "old" way to load CLR. The "new" way is through |
That's pretty much exaxtly what https://github.com/filmor/clr-loader does, with the added advantage that it also implements loaders for Mono and .Net Framework. It also uses hostfxr instead of the old style and works with .NET 5. |
Do you want to migrate it under pythonnet (as a separate repo) and publish a package? Does it need polishing? |
All of those things, yes. I'll move it under the project now. There are plenty of TODOs, in particular CI and testing. We can publish a package once it's actually used in pythonnet. |
I think it makes sense to publish package right away as 0.x "alpha", then add CI + testing. |
To simplify the build process (immensely), I'd like to move the CLR loading for Mono and CoreCLR to Python. I have a working prototype at https://gist.github.com/filmor/cf8a02aefff58be09a57ad2eca3cc246 for CoreCLR using CFFI and will work on an equivalent Mono implementation for this as well. For .NET Framework, I don't know of any public API to embed it into the currently running process, so we'll keep the existing loader for this one.
This implements the first section of the Plan(tm) (https://github.com/pythonnet/pythonnet/wiki/Plan#clr-loading).
The text was updated successfully, but these errors were encountered: