[Breaking change]: Single-file applications no longer always look for native libraries in executable directory #46356
Labels
breaking-change
Indicates a .NET Core breaking change
🗺️ reQUEST
Triggers an issue to be imported into Quest.
Description
Previously, in single-file .NET applications, the directory of the single-file executable was added to the
NATIVE_DLL_SEARCH_DIRECTORIES
property during startup. This means that the application directory was always probed when loading unmanaged libraries. On non-Windows with NativeAOT, the rpath was set to the application directory by default, such that it also always looked for native libraries in the application directory.The application directory is no longer added to
NATIVE_DLL_SEARCH_DIRECTORIES
in single-file and the rpath i setting has been removed in NativeAOT. In both cases,DllImportSearchPath.AssemblyDirectory
(included in the default behaviour for p/invokes) means the application directory - specifying that flag or leaving the default will look in the application directory. Specifying flags without that value will no longer look in the application directory.Issue: dotnet/runtime#114717
PR: dotnet/runtime#115236
Version
.NET 10 Preview 6
Previous behavior
Single-file applications always looked in the application directory when loading native libraries. NativeAOT applications on non-Windows always looked in the application directory when loading native libraries.
This meant that the following p/invoke would actually look in the application directory for
lib
and load it from there if it exists:New behavior
Single-file applications only look in the application directory if the search paths for a native library load indicate including the assembly directory.
Type of breaking change
Reason for change
The existing behaviour - always looking in the application directory even if search paths exclude it - has caused confusion in the past. It is also inconsistent with how the search flags are handled in regular (non-single-file, non-NativeAOT) .NET applications.
Recommended action
If the application/assembly directory is desired for a p/invoke or native library load and was not previously specified, specify
DllImportSearchPath.AssemblyDirectory
.If the RPATH setting is desired in NativeAOT, explicitly add the corresponding linker args to your project: https://learn.microsoft.com/dotnet/core/deploying/native-aot/interop#linking
Feature area
Interop
Affected APIs
The text was updated successfully, but these errors were encountered: