Reference#
Factory functions#
- clr_loader.get_mono(*, config_file: Optional[Union[str, PathLike[str]]] = None, global_config_file: Optional[Union[str, PathLike[str]]] = None, libmono: Optional[Union[str, PathLike[str]]] = None, sgen: bool = True, debug: bool = False, jit_options: Optional[Sequence[str]] = None, assembly_dir: Optional[str] = None, config_dir: Optional[str] = None, set_signal_chaining: bool = False, trace_mask: Optional[str] = None, trace_level: Optional[str] = None) Runtime#
Get a Mono runtime instance
- Parameters:
config_file – Path to the domain configuration file
global_config_file – Path to the global configuration file to load (defaults to, e.g.,
/etc/mono/config)libmono – Path to the Mono runtime dll/so/dylib. If this is not specified, we try to discover a globally installed instance using
find_libmono()sgen – If
libmonois not specified, this is passed tofind_libmono()debug – Whether to initialise Mono debugging
jit_options – “Command line options” passed to Mono’s
mono_jit_parse_optionsassembly_dir – The base directory for assemblies, passed to
mono_set_dirsconfig_dir – The base directory for configuration files, passed to
mono_set_dirsset_signal_chaining –
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
SIGPROF
SIGFPE
SIGQUIT
SIGUSR2
This currently only works on POSIX platforms
- clr_loader.get_coreclr(*, runtime_config: Optional[Union[str, PathLike[str]]] = None, entry_dll: Optional[Union[str, PathLike[str]]] = None, dotnet_root: Optional[Union[str, PathLike[str]]] = None, properties: Optional[Dict[str, str]] = None, runtime_spec: Optional[DotnetCoreRuntimeSpec] = None) Runtime#
Get a CoreCLR (.NET Core) runtime instance
The returned
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.- Parameters:
runtime_config – Path to a
runtimeconfig.jsonas generated bydotnet publish. If this parameter is not given, a temporary runtime config will be generated.entry_dll – The path to the entry dll. If this parameter is given, the runtime will be initialized using the command line hosting API instead of using the runtime config.
dotnet_root – The root directory of the .NET Core installation. If this is not specified, we try to discover it using
find_dotnet_root().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 usingfind_runtimes().
- clr_loader.get_netfx(*, domain: Optional[str] = None, config_file: Optional[Union[str, PathLike[str]]] = None) Runtime#
Get a .NET Framework runtime instance
- Parameters:
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.
Wrapper types#
- class clr_loader.Runtime#
CLR Runtime
Encapsulates the lifetime of a CLR (.NET) runtime. If the instance is deleted, the runtime will be shut down.
- get_assembly(assembly_path: Union[str, PathLike[str]]) 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
atexithandler.
- class clr_loader.Assembly(runtime: Runtime, path: Union[str, PathLike[str]])#
- get_function(name: str, func: Optional[str] = None) ClrFunction#
Get a wrapped .NET function instance
The function must be
static, and it must have the signatureint Func(IntPtr ptr, int size). The returned wrapped instance will take abinaryand call the .NET function with a pointer to that buffer and the buffer length. The buffer is reflected using CFFI’s from_buffer.- Parameters:
name – If
funcis not given, this is the fully qualified name of the function. Iffuncis given, this is the fully qualified name of the containing classfunc – Name of the function
- Returns:
A function object that takes a single
binaryparameter and returns anint
Utilities#
- 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) 6.12.0.122 (tarball) Runtime: Mono ============= Version: 6.12.0.122 (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.
- Returns:
Path to the .NET Core root
- clr_loader.find_libmono(*, assembly_dir: Optional[str] = None, sgen: bool = True) Path#
Find a suitable libmono dynamic library
On Windows and macOS, we check the default installation directories.
- Parameters:
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- Returns:
Path to usable
libmono
- clr_loader.find_runtimes() Iterator[DotnetCoreRuntimeSpec]#
Find installed .NET Core runtimes
If the
dotnetCLI can be found, we will call it asdotnet --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 thesharedsubdirectory.- Returns:
Iterable of
DotnetCoreRuntimeSpecobjects