diff --git a/core/hosting/src/NativeHost/nativehost.cpp b/core/hosting/src/NativeHost/nativehost.cpp index 0fd473025fd..981594689ee 100644 --- a/core/hosting/src/NativeHost/nativehost.cpp +++ b/core/hosting/src/NativeHost/nativehost.cpp @@ -309,6 +309,8 @@ namespace return false; // Load hostfxr and get desired exports + // NOTE: The .NET Runtime does not support unloading any of its native libraries. Running + // dlclose/FreeLibrary on any .NET libraries produces undefined behavior. void *lib = load_library(buffer); init_for_cmd_line_fptr = (hostfxr_initialize_for_dotnet_command_line_fn)get_export(lib, "hostfxr_initialize_for_dotnet_command_line"); init_for_config_fptr = (hostfxr_initialize_for_runtime_config_fn)get_export(lib, "hostfxr_initialize_for_runtime_config"); diff --git a/core/nativeaot/NativeLibrary/LoadLibrary.c b/core/nativeaot/NativeLibrary/LoadLibrary.c index bae153b8295..e4dedbab995 100644 --- a/core/nativeaot/NativeLibrary/LoadLibrary.c +++ b/core/nativeaot/NativeLibrary/LoadLibrary.c @@ -68,8 +68,7 @@ int callSumFunc(char *path, char *funcName, int firstInt, int secondInt) int result = MyImport(firstInt, secondInt); - // CoreRT libraries do not support unloading - // See https://github.com/dotnet/corert/issues/7887 + // NOTE: Native AOT libraries do not support unloading return result; } diff --git a/core/nativeaot/NativeLibrary/README.md b/core/nativeaot/NativeLibrary/README.md index 2a4a7ca5ad2..01aa97e1f3b 100644 --- a/core/nativeaot/NativeLibrary/README.md +++ b/core/nativeaot/NativeLibrary/README.md @@ -65,6 +65,8 @@ The last thing to do is to actually call the method we have imported. int result = MyImport(5,3); ``` +Note that the .NET Runtime does not support unloading. Once a handle to the shared library is created, the library cannot be closed with `dlclose/FreeLibrary`. + ## Exporting methods For a C# method in the native library to be consumable by external programs, it has to be explicitly exported using the `[UnmanagedCallersOnly]` attribute.