Skip to content

Improve error message when failing to load runtime #75

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

Open
egaudrain opened this issue Feb 26, 2025 · 1 comment
Open

Improve error message when failing to load runtime #75

egaudrain opened this issue Feb 26, 2025 · 1 comment

Comments

@egaudrain
Copy link

When using:

import clr_loader
clr_loader.get_coreclr()

If the loading fails, we merely get this error:

RuntimeError: Could not find a suitable hostfxr library in /usr/local/share/dotnet

This is not very easy to debug because we don't know why the hostfxr might not be suitable.

The culprit is this piece of code, which just silences the error:

try:
return ffi.dlopen(str(hostfxr_path))
except Exception:
pass

I get that, in the logic of the code, if a runtime is found, we don't want to display a whole bunch of clutter... But in the case where no runtime was found, it seems helpful to have some more details?

For instance, after digging, I found that the reason the runtime was not loading was:

(mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

Because Python is a universal binary, it is a bit unpredictable whether it is ran as arm64 or x86_64, and because .NET is available in the two flavours.... but the installed files don't seem to be marked with the architecture... that makes the whole thing a little tricky to debug.

@filmor
Copy link
Member

filmor commented Feb 26, 2025

I'm very open to PRs that improve this. E.g. one could collect the exceptions and, when the search finally fails, include a summary of paths tried and the corresponding exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants