@@ -20,9 +20,8 @@ def __init__(self, runtime_config: Path, dotnet_root: Path, **params: str):
2020
2121 self ._dotnet_root = Path (dotnet_root )
2222 self ._dll = load_hostfxr (self ._dotnet_root )
23- self ._is_initialized = False
2423 self ._handle = _get_handle (self ._dll , self ._dotnet_root , runtime_config )
25- self ._load_func = _get_load_func ( self . _dll , self . _handle )
24+ self ._load_func = None
2625
2726 for key , value in params .items ():
2827 self [key ] = value
@@ -36,7 +35,7 @@ def dotnet_root(self) -> Path:
3635
3736 @property
3837 def is_initialized (self ) -> bool :
39- return self ._is_initialized
38+ return self ._load_func is not None
4039
4140 @property
4241 def is_shutdown (self ) -> bool :
@@ -81,18 +80,23 @@ def __iter__(self) -> Generator[Tuple[str, str], None, None]:
8180 for i in range (size_ptr [0 ]):
8281 yield (decode (keys_ptr [i ]), decode (values_ptr [i ]))
8382
83+ def _get_load_func (self ):
84+ if self ._load_func is None :
85+ self ._load_func = _get_load_func (self ._dll , self ._handle )
86+
87+ return self ._load_func
88+
8489 def _get_callable (self , assembly_path : StrOrPath , typename : str , function : str ):
8590 # TODO: Maybe use coreclr_get_delegate as well, supported with newer API
8691 # versions of hostfxr
87- self ._is_initialized = True
8892
8993 # Append assembly name to typename
9094 assembly_path = Path (assembly_path )
9195 assembly_name = assembly_path .stem
9296 typename = f"{ typename } , { assembly_name } "
9397
9498 delegate_ptr = ffi .new ("void**" )
95- res = self ._load_func (
99+ res = self ._get_load_func () (
96100 encode (str (assembly_path )),
97101 encode (typename ),
98102 encode (function ),
@@ -103,12 +107,6 @@ def _get_callable(self, assembly_path: StrOrPath, typename: str, function: str):
103107 check_result (res )
104108 return ffi .cast ("component_entry_point_fn" , delegate_ptr [0 ])
105109
106- def _check_initialized (self ) -> None :
107- if self ._handle is None :
108- raise RuntimeError ("Runtime is shut down" )
109- elif not self ._is_initialized :
110- raise RuntimeError ("Runtime is not initialized" )
111-
112110 def shutdown (self ) -> None :
113111 if self ._handle is not None :
114112 self ._dll .hostfxr_close (self ._handle )
0 commit comments