From dc61c4696ea238ee66ed3870f22042fc4e826c95 Mon Sep 17 00:00:00 2001 From: Etienne Gaudrain Date: Thu, 27 Feb 2025 15:58:19 +0100 Subject: [PATCH] Added extra info about error when hostfxr not found or loaded properly. https://github.com/pythonnet/clr-loader/issues/75 --- clr_loader/ffi/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/clr_loader/ffi/__init__.py b/clr_loader/ffi/__init__.py index 23debae..289999d 100644 --- a/clr_loader/ffi/__init__.py +++ b/clr_loader/ffi/__init__.py @@ -23,18 +23,20 @@ def load_hostfxr(dotnet_root: Path): hostfxr_path = dotnet_root / "host" / "fxr" hostfxr_paths = hostfxr_path.glob(f"?.*/{hostfxr_name}") + error_report = list() + for hostfxr_path in reversed(sorted(hostfxr_paths, key=_path_to_version)): try: return ffi.dlopen(str(hostfxr_path)) - except Exception: - pass + except Exception as err: + error_report.append(f"Path {hostfxr_path} gave the following error:\n{err}") try: return ffi.dlopen(str(dotnet_root / hostfxr_name)) - except Exception: - pass + except Exception as err: + error_report.append(f"Path {hostfxr_path} gave the following error:\n{err}") - raise RuntimeError(f"Could not find a suitable hostfxr library in {dotnet_root}") + raise RuntimeError(f"Could not find a suitable hostfxr library in {dotnet_root}. The following paths were scanned:\n\n"+("\n\n".join(error_report))) def load_mono(path: Optional[Path] = None):