* Add ability for hostfxr_get_runtime_delegate to block on invalid delegate types.
This is required so that the runtime isn't loaded if the request has no chance of succeeding.
Fix spelling of initialization_options_t.
Add context_contract_version_set flag to initialization_options_t.
This allows hostpolicy to know whether it can rely on the version field of corehost_context_contract to be valid.
Also always initialize corehost_context_contract to {}.
* Allow app-based context to call hostfxr_get_runtime_delegate.
Currently, it may only request the load_assembly_and_get_function_pointer delegate.
Fix discrepancy in design doc.
Add error code HostApiUnsupportedScenario for blocks that might be removed. This gives the native host better information on why the request failed.
Add tests for running a component from an app context.
14 KiB
Hosting layer error and exit codes
This document lists all the values returned as special exit codes when running dotnet.exe or apphost or returned by the hosting APIs (hostfxr, hostpolicy and nethost).
Note that the exit code returned by running an application via dotnet.exe or apphost can either be one of the below values or the exit code of the managed application itself.
Success error/exit codes
-
Success(0) - Operation was successful. -
Success_HostAlreadyInitialized(0x00000001) - Initialization was successful, but another host context is already initialized, so the returned context is "secondary". The requested context was otherwise fully compatible with the already initialized context.
This is returned byhostfxr_initialize_for_runtime_configif it's called when the host is already initialized in the process. Comes fromcorehost_initializeinhostpolicy. -
Success_DifferentRuntimeProperties(0x00000002) - Initialization was successful, but another host context is already initialized and the requested context specified some runtime properties which are not the same (either in value or in presence) to the already initialized context. This is returned byhostfxr_initialize_for_runtime_configif it's called when the host is already initialized in the process. Comes fromcorehost_initializeinhostpolicy.
Failure error/exit codes
-
InvalidArgFailure(0x80008081) - One of the specified arguments for the operation is invalid. -
CoreHostLibLoadFailure(0x80008082) - There was a failure loading a dependent library. If any of the hosting components callsLoadLibrary/dlopenon a dependent library and the call fails, this error code is returned. The most common case for this failure is if the dependent library is missing some of its dependencies (for example the necessary CRT is missing on the machine), likely corrupt or incomplete install.
This error code is also returned fromcorehost_resolve_component_dependenciesif it's called on ahostpolicywhich has not been initialized via the hosting layer. This would typically happen ifcoreclris loaded directly without the hosting layer and thenAssemblyDependencyResolveris used (which is an unsupported scenario). -
CoreHostLibMissingFailure(0x80008083) - One of the dependent libraries is missing. Typically when thehostfxr,hostpolicyorcoreclrdynamic libraries are not present in the expected locations. Probably means corrupted or incomplete installation. -
CoreHostEntryPointFailure(0x80008084) - One of the dependent libraries is missing a required entry point. -
CoreHostCurHostFindFailure(0x80008085) - If the hosting component is trying to use the path to the current module (the hosting component itself) and from it deduce the location of the installation. Either the location of the current module could not be determined (some weird OS call failure) or the location is not in the right place relative to other expected components.
For example thehostfxrmay look at its location and try to deduce the location of thesharedfolder with the framework from it. It assumes the typical install layout on disk. If this doesn't work, this error will be returned. -
CoreClrResolveFailure(0x80008087) - If thecoreclrlibrary could not be found. The hosting layer (hostpolicy) looks forcoreclrlibrary either next to the app itself (for self-contained) or in the root framework (for framework-dependent). This search can be done purely by looking at disk or more commonly by looking into the respective.deps.json. If thecoreclrlibrary is missing in.deps.jsonor it's there but doesn't exist on disk, this error is returned. -
CoreClrBindFailure(0x80008088) - The loadedcoreclrlibrary doesn't have one of the required entry points. -
CoreClrInitFailure(0x80008089) - The call tocoreclr_initializefailed. The actual error returned bycoreclris reported in the error message. -
CoreClrExeFailure(0x8000808a) - The call tocoreclr_execute_assemblyfailed. Note that this does not mean anything about the app's exit code, this failure occurs ifcoreclrfailed to run the app itself. -
ResolverInitFailure(0x8000808b) - Initialization of thehostpolicydependency resolver failed. This can be:- One of the frameworks or the app is missing a required
.deps.jsonfile. - One of the
.deps.jsonfiles is invalid (invalid JSON, or missing required properties and so on).
- One of the frameworks or the app is missing a required
-
ResolverResolveFailure(0x8000808c) - Resolution of dependencies inhostpolicyfailed. This can mean many different things, but in general one of the processed.deps.jsoncontains entry for a file which could not found, or its resolution failed for some other reason (conflict for example). -
LibHostCurExeFindFailure(0x8000808d) - Failure to determine the location of the current executable. The hosting layer uses the current executable path to deduce the install location in some cases. If this path can't be obtained (OS call fails, or the returned path doesn't exist), this error is returned. -
LibHostInitFailure(0x8000808e) - Initialization of thehostpolicylibrary failed. Thecorehost_loadmethod takes a structure with lot of initialization parameters. If the version of this structure doesn't match the expected value, this error code is returned. This would in general mean incompatibility between thehostfxrandhostpolicy, which should really only happen if somehow a newerhostpolicyis used by olderhostfxr. This typically means corrupted installation. -
LibHostSdkFindFailure(0x80008091) - Failure to find the requested SDK. This happens in thehostfxrwhen an SDK (also called CLI) command is used withdotnet. In this case the hosting layer tries to find an installed .NET SDK to run the command on. The search is based on deduced install location and on the requested version from potentialglobal.jsonfile. If either no matching SDK version can be found, or that version exists, but it's missing thedotnet.dllfile, this error code is returned. -
LibHostInvalidArgs(0x80008092) - Arguments tohostpolicyare invalid. This is used in three unrelated places in thehostpolicy, but in all cases it means the component callinghostpolicydid something wrong:- Command line arguments for the app - the failure would typically mean that wrong argument was passed or such. For example if the application main assembly is not specified on the command line. On its own this should not happen as
hostfxrshould have parsed and validated all command line arguments. hostpolicycontext'sget_delegate- if the requested delegate enum value is not recognized. Again this would meanhostfxrpassed the wrong value.corehost_resolve_component_dependencies- if something went wrong initializinghostpolicyinternal structures. Would happen for example when thecomponent_main_assembly_pathargument is wrong.
- Command line arguments for the app - the failure would typically mean that wrong argument was passed or such. For example if the application main assembly is not specified on the command line. On its own this should not happen as
-
InvalidConfigFile(0x80008093) - The.runtimeconfig.jsonfile is invalid. The reasons for this failure can be among these:- Failure to read from the file
- Invalid JSON
- Invalid value for a property (for example number for property which requires a string)
- Missing required property
- Other inconsistencies (for example
rollForwardandapplyPatchesare not allowed to be specified in the same config file) - Any of the above failures reading the
.runtimecofig.dev.jsonfile - Self-contained
.runtimeconfig.jsonused inhostfxr_initialize_for_runtime_configNote that missing.runtimconfig.jsonis not an error (means self-contained app).
This error code is also used when there is a problem reading the CLSID map file incomhost.
-
AppArgNotRunnable(0x80008094) - Used internally when the command line fordotnet.exedoesn't contain path to the application to run. In such case the command line is considered to be a CLI/SDK command. This error code should never be returned to external caller. -
AppHostExeNotBoundFailure(0x80008095) -apphostfailed to determine which application to run. This can mean:- The
apphostbinary has not been imprinted with the path to the app to run (so freshly builtapphost.exefrom the branch will fail to run like this) - The
apphostis a bundle (single-file exe) and it failed to extract correctly.
- The
-
FrameworkMissingFailure(0x80008096) - It was not possible to find a compatible framework version. This originates inhostfxr(resolve_framework_reference) and means that the app specified a reference to a framework in its.runtimeconfig.jsonwhich could not be resolved. The failure to resolve can mean that no such framework is available on the disk, or that the available frameworks don't match the minimum version specified or that the roll forward options specified excluded all available frameworks.
Typically this would be used if a 3.0 app is trying to run on a machine which has no 3.0 installed.
It would also be used for example if a 32bit 3.0 app is running on a machine which has 3.0 installed but only for 64bit. -
HostApiFailed(0x80008097) - Returned byhostfxr_get_native_search_directoriesif thehostpolicycould not calculate theNATIVE_DLL_SEARCH_DIRECTORIES. -
HostApiBufferTooSmall(0x80008098) - Returned when the buffer specified to an API is not big enough to fit the requested value. Can be returned from:hostfxr_get_runtime_propertieshostfxr_get_native_search_directoriesget_hostfxr_path
-
LibHostUnknownCommand(0x80008099) - Returned byhostpolicyif thecorehost_main_with_output_bufferis called with unsupported host command. This error code means there is incompatibility between thehostfxrandhostpolicy. In reality this should pretty much never happen. -
LibHostAppRootFindFailure(0x8000809a) - Returned byapphostif the imprinted application path doesn't exist. This would happen if the app is built with an executable (theapphost) and the mainapp.dllis missing. -
SdkResolverResolveFailure(0x8000809b) - Returned fromhostfxr_resolve_sdk2when it fails to find matching SDK. Similar toLibHostSdkFindFailurebut only used in thehostfxr_resolve_sdk2. -
FrameworkCompatFailure(0x8000809c) - During processing of.runtimeconfig.jsonthere were two framework references to the same framework which were not compatible. This can happen if the app specified a framework reference to a lower-level framework which is also specified by a higher-level framework which is also used by the app.
For example, this would happen if the app referencedMicrosoft.AspNet.Appversion 2.0 andMicrosoft.NETCore.Appversion 3.0. In such case theMicrosoft.AspNet.Apphas.runtimeconfig.jsonwhich also referencesMicrosoft.NETCore.Appbut it only allows versions 2.0 up to 2.9 (via roll forward options). So the version 3.0 requested by the app is incompatible. -
FrameworkCompatRetry(0x8000809d) - Error used internally if the processing of framework references from.runtimeconfig.jsonreached a point where it needs to reprocess another already processed framework reference. If this error is returned to the external caller, it would mean there's a bug in the framework resolution algorithm. -
AppHostExeNotBundle(0x8000809e) - Error reading the bundle footer metadata from a single-fileapphost. This would mean a corruptedapphost. -
BundleExtractionFailure(0x8000809f) - Error extracting single-fileapphostbundle. This is used in case of any error related to the bundle itself. Typically would mean a corrupted bundle. -
BundleExtractionIOError(0x800080a0) - Error reading or writing files during single-fileapphostbundle extraction. -
LibHostDuplicateProperty(0x800080a1) - The.runtimeconfig.jsonspecified by the app contains a runtime property which is also produced by the hosting layer. For example if the.runtimeconfig.jsonwould specify a propertyTRUSTED_PLATFORM_ROOTS, this error code would be returned. It is not allowed to specify properties which are otherwise populated by the hosting layer (hostpolicy) as there is not good way to resolve such conflicts. -
HostApiUnsupportedVersion(0x800080a2) - Feature which requires certain version of the hosting layer binaries was used on a version which doesn't support it.
For example if COM component specified to run on 2.0Microsoft.NETCore.App- as that contains older version ofhostpolicywhich doesn't support the necessary features to provide COM services. -
HostInvalidState(0x800080a3) - Error code returned by the hosting APIs inhostfxrif the current state is incompatible with the requested operation. There are many such cases, please refer to the documentation of the hosting APIs for details.
For example ifhostfxr_get_runtime_property_valueis called with thehost_context_handlenullptr(meaning get property from the active runtime) but there's no active runtime in the process. -
HostPropertyNotFound(0x800080a4) - property requested byhostfxr_get_runtime_property_valuedoesn't exist. -
CoreHostIncompatibleConfig(0x800080a5) - Error returned byhostfxr_initialize_for_runtime_configif the component being initialized requires framework which is not available or incompatible with the frameworks loaded by the runtime already in the process. For example trying to load a component which requires 3.0 into a process which is already running a 2.0 runtime. -
HostApiUnsupportedScenario(0x800080a6) - Error returned byhostfxr_get_runtime_delegatewhenhostfxrdoesn't currently support requesting the given delegate type using the given context.