-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Description
The DllImportSearchPath flags allow specification of where to search when looking up libraries for a p/invoke or an explicit native library load - for example, in DefaultDllImportSearchPathsAttribute or a NativeLibrary API.
The AssemblyDirectory value indicates that the directory containing the assembly of the p/invoke itself should be searched first. Previously, if AssemblyDirectory was specified as the only search flag, the runtime would look in the assembly directory and if the library is not found, then fall back to the OS search behaviour. This has been updated to remove the fallback. If AssemblyDirectory is specified as the only search flag, the runtime will only look in the assembly directory.
Issue: dotnet/runtime#107040
PR: dotnet/runtime#114756
Version
.NET 10 Preview 5
Previous behavior
When DllImportSearchPath.AssemblyDirectory was specified as the only search flag, the runtime searched the assembly directory first, but then fell back to the operating system's default library search behavior.
New behavior
When DllImportSearchPath.AssemblyDirectory is specified as the only search flag, the runtime searches only in the assembly directory and does not fall back to the operating system's default library search behavior.
Type of breaking change
- Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
- Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
- Behavioral change: Existing binaries might behave differently at run time.
Reason for change
The fallback behaviour of specifying DllImportSearchPath.AssemblyDirectory has caused confusion for users in the past. It is also inconsistent with how flags are generally designed.
Recommended action
If the fallback behaviour is desired, do not specify an explicit DllImportSearchPath. By default, if no flags are specified, the runtime will search the assembly directory and then fall back to the OS load
Feature area
Interop
Affected APIs
- P/Invokes using
DefaultDllImportSearchPaths NativeLibrary.LoadNativeLibrary.TryLoad