clr-loader is a pure Python library designed for loading .NET runtimes (CoreCLR, Mono, Full .NET Framework), loading .NET assemblies, and interacting with them. It primarily serves as a low-level backend for the pythonnet library but can be used standalone for specific scenarios. Version 0.3.0 is the current release, requiring Python 3.10 or newer. Releases are made on an as-needed basis, often in sync with pythonnet development.
pip install clr-loaderVerified import paths — ran on the pinned version, not inferred.
This example attempts to load the CoreCLR runtime automatically. It demonstrates the most basic interaction with clr-loader and includes error handling for common setup issues, specifically the absence of a discoverable .NET runtime on the system. Advanced usage, such as loading specific assemblies or interacting with .NET objects, typically involves the pythonnet library built on top of clr-loader.
Upgrade your Python environment to 3.10 or later, or use an older version of clr-loader if compatible with your Python version and needs (though not recommended for long-term projects).
Ensure a compatible .NET runtime is installed on your system. For CoreCLR, this typically means installing a .NET SDK or Runtime, which should make `dotnet` command available in your PATH. If auto-discovery fails, you might need to provide `runtime_config` or `home_directory` arguments to `get_coreclr()`.
For most use cases involving interacting with .NET libraries from Python, consider using `pythonnet` which provides a high-level API built on `clr-loader`.
Always import `get_coreclr` and `get_mono` directly from the top-level `clr_loader` package (e.g., `from clr_loader import get_coreclr`).
Ensure 'clr-loader' is correctly installed using `pip install clr-loader`. If using a specific virtual environment (e.g., Anaconda), activate that environment before installation. A Python kernel or IDE restart might be necessary to recognize the newly installed package.
Verify that the appropriate .NET SDK or Runtime is installed on your system. For CoreCLR, ensure the `DOTNET_ROOT` environment variable is set to the correct installation path. For packaged applications (e.g., with PyInstaller), confirm that `ClrLoader.dll` and other required runtime files are correctly bundled and accessible by the executable.
Upgrade your `pythonnet` installation to a version compatible with `clr-loader` 0.3.0 and Python 3.10+. This can often be resolved by running `pip install --upgrade --pre pythonnet` to get the latest compatible pre-release or stable version of pythonnet.
Ensure that the .NET assembly you are trying to load, along with all its dependent DLLs, are present in the application's execution directory or a location discoverable by the .NET runtime. Check for x86/x64 architecture mismatches between your Python environment, `clr-loader`, and the .NET assembly. For detailed diagnostics, use the .NET Fusion Log Viewer (`fuslogvw.exe`) to understand assembly binding failures.
No dependency data recorded yet.