- clr_loader.get_mono(*, config_file: str | PathLike | None = None, global_config_file: str | PathLike | None = None, libmono: str | PathLike | None = None, sgen: bool = True, debug: bool = False, jit_options: Sequence[str] | None = None, assembly_dir: str | None = None, config_dir: str | None = None, set_signal_chaining: bool = False) Runtime #
Get a Mono runtime instance
config_file – Path to the domain configuration file
global_config_file – Path to the global configuration file to load (defaults to, e.g.,
libmono – Path to the Mono runtime dll/so/dylib. If this is not specified, we try to discover a globally installed instance using
sgen – If
libmonois not specified, this is passed to
debug – Whether to initialise Mono debugging
jit_options – “Command line options” passed to Mono’s
assembly_dir – The base directory for assemblies, passed to
config_dir – The base directory for configuration files, passed to
Whether to enable signal chaining, passed to
mono_set_signal_chaining. If it is enabled, the runtime saves the original signal handlers before installing its own, and calls the original ones in the following cases:
SIGSEGV/SIGABRT while executing native code
This currently only works on POSIX platforms
- clr_loader.get_coreclr(*, runtime_config: str | PathLike | None = None, dotnet_root: str | PathLike | None = None, properties: Dict[str, str] | None = None, runtime_spec: DotnetCoreRuntimeSpec | None = None) Runtime #
Get a CoreCLR (.NET Core) runtime instance
DotnetCoreRuntimealso acts as a mapping of the config properties. They can be retrieved using the index operator and can be written until the runtime is initialized. The runtime is initialized when the first function object is retrieved.
runtime_config – Pass to a
runtimeconfig.jsonas generated by
dotnet publish. If this parameter is not given, a temporary runtime config will be generated.
dotnet_root – The root directory of the .NET Core installation. If this is not specified, we try to discover it using
properties – Additional runtime properties. These can also be passed using the
configPropertiessection in the runtime config.
runtime_spec – If the
runtime_configis not specified, the concrete runtime to use can be controlled by passing this parameter. Possible values can be retrieved using
- clr_loader.get_netfx(*, domain: str | None = None, config_file: str | PathLike | None = None) Runtime #
Get a .NET Framework runtime instance
domain – Name of the domain to create. If no value is passed, assemblies will be loaded into the root domain.
config_file – Configuration file to use to initialize the
AppDomain. This will only be used for non-root-domains as we can not control the configuration of the implicitly loaded root domain.
- class clr_loader.Runtime#
Encapsulates the lifetime of a CLR (.NET) runtime. If the instance is deleted, the runtime will be shut down.
- get_assembly(assembly_path: str | PathLike) Assembly #
Get an assembly wrapper
This function does not guarantee that the respective assembly is or can be loaded. Due to the design of the different hosting APIs, loading only happens when the first function is referenced, and only then potential errors will be raised.
- abstract info() RuntimeInfo #
Get configuration and version information
- abstract shutdown() None #
Shut down the runtime as much as possible
Implementations should still be able to “reinitialize”, thus the final cleanup will usually happen in an
- class clr_loader.Assembly(runtime: Runtime, path: str | PathLike)#
- get_function(name: str, func: str | None = None) ClrFunction #
Get a wrapped .NET function instance
The function must be
static, and it must have the signature
int Func(IntPtr ptr, int size). The returned wrapped instance will take a
binaryand call the .NET function with a pointer to that buffer and the buffer length. The buffer is reflected using CFFI’s from_buffer.
name – If
funcis not given, this is the fully qualified name of the function. If
funcis given, this is the fully qualified name of the containing class
func – Name of the function
A function object that takes a single
binaryparameter and returns an
- class clr_loader.RuntimeInfo(kind: str, version: str, initialized: bool, shutdown: bool, properties: Dict[str, str])#
Information on a Runtime instance
An informative text can be retrieved from this by converting it to a
str, in particular the following results in readable debug information:
>>> ri = RuntimeInfo() >>> print(ri) 184.108.40.206 (tarball) Runtime: Mono ============= Version: 220.127.116.11 (tarball) Initialized: True Shut down: False Properties:
- class clr_loader.DotnetCoreRuntimeSpec(name: str, version: str, path: Path)#
Specification of an installed .NET Core runtime
- clr_loader.find_dotnet_root() Path #
Try to discover the .NET Core root directory
If the environment variable
DOTNET_ROOTis defined, we will use that. Otherwise, we probe the default installation paths on Windows and macOS.
If none of these lead to a result, we try to discover the
dotnetCLI tool and use its (real) parent directory.
Otherwise, this function raises an exception.
Path to the .NET Core root
- clr_loader.find_libmono(*, assembly_dir: str | None = None, sgen: bool = True) Path #
Find a suitable libmono dynamic library
On Windows and macOS, we check the default installation directories.
sgen – Whether to look for an SGen or Boehm GC instance. This parameter is ignored on Windows, as only
sgenis installed with the default installer
Path to usable
- clr_loader.find_runtimes() Iterator[DotnetCoreRuntimeSpec] #
Find installed .NET Core runtimes
dotnetCLI can be found, we will call it as
dotnet --list-runtimesand parse the result.
If it is not available, we try to discover the dotnet root directory using
find_dotnet_root()and enumerate the runtimes installed in the