Struct netcorehost::hostfxr::HostfxrContext
source · pub struct HostfxrContext<I> { /* private fields */ }
netcore3_0
only.Expand description
State which hostfxr creates and maintains and represents a logical operation on the hosting components.
Implementations§
source§impl<I> HostfxrContext<I>
impl<I> HostfxrContext<I>
sourcepub unsafe fn from_handle(
handle: HostfxrHandle,
hostfxr: Hostfxr,
is_primary: bool
) -> Self
pub unsafe fn from_handle( handle: HostfxrHandle, hostfxr: Hostfxr, is_primary: bool ) -> Self
Creates a new context from the given handle.
§Safety
The context handle has to be match the context type I
.
If the context was initialized using initialize_for_dotnet_command_line
I
has to be InitializedForCommandLine
.
If the context was initialized using initialize_for_runtime_config
I
has to be InitializedForRuntimeConfig
.
sourcepub const fn handle(&self) -> HostfxrHandle
pub const fn handle(&self) -> HostfxrHandle
Gets the underlying handle to the hostfxr context.
sourcepub fn into_handle(self) -> HostfxrHandle
pub fn into_handle(self) -> HostfxrHandle
Gets the underlying handle to the hostfxr context and consume this context.
sourcepub const fn is_primary(&self) -> bool
pub const fn is_primary(&self) -> bool
Gets whether the context is the primary hostfxr context. There can only be a single primary context in a process.
§Note
sourcepub fn get_runtime_delegate(
&self,
type: hostfxr_delegate_type
) -> Result<RawFunctionPtr, HostingError>
pub fn get_runtime_delegate( &self, type: hostfxr_delegate_type ) -> Result<RawFunctionPtr, HostingError>
Gets a typed delegate from the currently loaded CoreCLR
or from a newly created one.
You propably want to use get_delegate_loader
or get_delegate_loader_for_assembly
instead of this function if you want to load function pointers.
§Remarks
If the context was initialized using initialize_for_runtime_config
, then all delegate types are supported.
If it was initialized using initialize_for_dotnet_command_line
, then only the following
delegate types are currently supported:
sourcepub fn get_delegate_loader(&self) -> Result<DelegateLoader, HostingError>
pub fn get_delegate_loader(&self) -> Result<DelegateLoader, HostingError>
Gets a delegate loader for loading an assembly and contained function pointers.
sourcepub fn get_delegate_loader_for_assembly(
&self,
assembly_path: impl Into<PdCString>
) -> Result<AssemblyDelegateLoader, HostingError>
pub fn get_delegate_loader_for_assembly( &self, assembly_path: impl Into<PdCString> ) -> Result<AssemblyDelegateLoader, HostingError>
Gets a delegate loader for loading function pointers of the assembly with the given path. The assembly will be loaded lazily when the first function pointer is loaded.
sourcepub fn load_assembly_from_path(
&self,
assembly_path: impl AsRef<PdCStr>
) -> Result<(), HostingError>
pub fn load_assembly_from_path( &self, assembly_path: impl AsRef<PdCStr> ) -> Result<(), HostingError>
Loads the specified assembly in the default load context from the given path.
It uses AssemblyDependencyResolver
to register additional dependency resolution for the load context.
Function pointers to methods in the assembly can then be loaded using a DelegateLoader
.
sourcepub fn load_assembly_from_bytes(
&self,
assembly_bytes: impl AsRef<[u8]>,
symbols_bytes: impl AsRef<[u8]>
) -> Result<(), HostingError>
pub fn load_assembly_from_bytes( &self, assembly_bytes: impl AsRef<[u8]>, symbols_bytes: impl AsRef<[u8]> ) -> Result<(), HostingError>
Loads the specified assembly in the default load context from the given buffers.
It does not provide a mechanism for registering additional dependency resolution, as mechanisms like .deps.json
and AssemblyDependencyResolver
are file-based.
Dependencies can be pre-loaded (for example, via a previous call to this function) or the specified assembly can explicitly register its own resolution logic (for example, via the AssemblyLoadContext.Resolving
event).
It uses AssemblyDependencyResolver
to register additional dependency resolution for the load context.
Function pointers to methods in the assembly can then be loaded using a DelegateLoader
.
sourcepub fn close(self) -> Result<HostingSuccess, HostingError>
pub fn close(self) -> Result<HostingSuccess, HostingError>
Closes an initialized host context. This method is automatically called on drop, but can be explicitely called to handle errors during closing.
source§impl HostfxrContext<InitializedForCommandLine>
impl HostfxrContext<InitializedForCommandLine>
sourcepub fn run_app(self) -> AppOrHostingResult
pub fn run_app(self) -> AppOrHostingResult
Load the dotnet runtime and run the application.
§Return value
If the app was successfully run, the exit code of the application. Otherwise, the error code result.
source§impl<I> HostfxrContext<I>
impl<I> HostfxrContext<I>
sourcepub fn get_runtime_property_value(
&self,
name: impl AsRef<PdCStr>
) -> Result<&PdCStr, HostingError>
pub fn get_runtime_property_value( &self, name: impl AsRef<PdCStr> ) -> Result<&PdCStr, HostingError>
Gets the runtime property value for the given key of this host context.
sourcepub fn set_runtime_property_value(
&mut self,
name: impl AsRef<PdCStr>,
value: impl AsRef<PdCStr>
) -> Result<(), HostingError>
pub fn set_runtime_property_value( &mut self, name: impl AsRef<PdCStr>, value: impl AsRef<PdCStr> ) -> Result<(), HostingError>
Sets the value of a runtime property for this host context.
sourcepub fn remove_runtime_property_value(
&mut self,
name: impl AsRef<PdCStr>
) -> Result<(), HostingError>
pub fn remove_runtime_property_value( &mut self, name: impl AsRef<PdCStr> ) -> Result<(), HostingError>
Remove a runtime property for this host context.
sourcepub fn runtime_properties(
&self
) -> Result<HashMap<&PdCStr, &PdCStr>, HostingError>
pub fn runtime_properties( &self ) -> Result<HashMap<&PdCStr, &PdCStr>, HostingError>
Get all runtime properties for this host context.