pythonnet / clr-loader

Loader for different .NET runtimes
MIT License
32 stars 23 forks source link

clr_loader.ffi.load_hostfxr might not load the latest version of hostfxr #38

Closed sdao closed 2 years ago

sdao commented 2 years ago

Environment

Details

Depending on the contents of C:\Program Files\dotnet\host\fxr (or wherever the dotnet root is), clr_loader might pick up an older version of hostfxr based on the logic in def load_hostfxr(dotnet_root: Path)

e.g. if the contents of the folder are

2.1.7
3.1.26
5.0.5
5.0.17

then it doesn't pick up 5.0.17, but picks up 5.0.5 because Python's lexicographic sort will order the folder as ['2.1.7', '3.1.26', '5.0.17', '5.0.5'].

This is admittedly very minor, but we just ran into this and wanted to give a heads up :) Thank you!

sdao commented 2 years ago

Oh crap, I realized this should have probably gone to the clr-loader repo. But I'm not sure if I can move it myself.

filmor commented 2 years ago

Could you check whether the newest fixes this for you? I'll have a look later whether I can just port https://github.com/dotnet/runtime/blob/20e5237104ddd178f12bc501352e45a5e91e5048/src/native/corehost/fxr_resolver.cpp#L12 to Python to get the exact behaviour that the nethost library applies, but this should probably already do.

sdao commented 2 years ago

Yep, I can confirm that it picks up the expected version of hostfxr (e.g. 6.0.10 over 6.0.9) now. Thank you!

filmor commented 2 years ago

Fixed in v0.2.4, thank you for the detailed report :)