Repository navigation
Pass correct search path to DllImportResolver for default flags on Mono - #129831
Merged
elinor-fung merged 1 commit intoJun 25, 2026
Merged
Conversation
When neither the P/Invoke nor the assembly has a DefaultDllImportSearchPaths attribute, Mono passed DllImportSearchPath.AssemblyDirectory to a registered DllImportResolver instead of null. lookup_pinvoke_call_impl defaults the flags to ASSEMBLY_DIRECTORY for the built-in probing logic, and netcore_resolve_with_dll_import_resolver derived "has search flags" from (flags != 0), so the defaulted value leaked to the resolver. Combined with dotnet#114756 - which made an explicit AssemblyDirectory no longer fall back to the OS search - this broke resolvers that forward the search path to NativeLibrary.Load, such as loading iOS @rpath frameworks. Thread the existing user_specified_flags signal through to the resolver so it receives the attribute value, or null when none was specified, matching CoreCLR and NativeAOT. Fixes dotnet#129798 Co-authored-by: Copilot <[email protected]>
elinor-fung
requested review from
steveisok,
thaystg and
vitek-karas
as code owners
June 25, 2026 00:41
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Mono’s DllImportResolver searchPath reporting so that the resolver receives null when no DefaultDllImportSearchPaths attribute is present, instead of receiving Mono’s internal default (AssemblyDirectory). This brings Mono behavior in line with the documented DllImportResolver contract and with CoreCLR/NativeAOT.
Changes:
- Mono: thread through and use
user_specified_flagsto decide whether to pass search flags to the resolver (instead offlags != 0). - Tests: add an interop test validating that the resolver observes
AssemblyDirectory,System32,LegacyBehavior, andnullbased on attribute presence/value.
Show a summary per file
| File | Description |
|---|---|
| src/mono/mono/metadata/native-library.c | Uses the existing user_specified_flags signal to decide whether the resolver should receive a non-null searchPath. |
| src/tests/Interop/DllImportSearchPaths/DllImportSearchPathsTest.cs | Adds coverage to assert the resolver’s observed searchPath matches DefaultDllImportSearchPaths (or null when absent). |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 2
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to |
Merged
2 of 4 tasks
JulieLeeMSFT
pushed a commit
that referenced
this pull request
Jun 29, 2026
…ult flags on Mono (#129862) Backport of #129831 to release/10.0 /cc @elinor-fung ## Customer Impact - [x] Customer reported - [ ] Found internally Customer reported in #129798. On Mono, when no search flags are user-specified, the runtime ends up passing an explicit `DllImportSeachPath.AssemblyDirectory` value was passed to any registered `DllImportResolver` instead of null. The expected DllImportResolver contract is that search path is the attribute value, or null when neither the P/Invoke nor the assembly has the attribute. Before #114756, specifying only `DllImportSearchPath.AssemblyDirectory` would still do the default search, so the Mono behaviour of explicitly passing `AssemblyDirectory` instead of null didn't really matter. After that change, specifying only `DllImportSeachPath.AssemblyDirectory` meant only assembly directory. This means that when a resolver that forwards the (wrongly non-null) AssemblyDirectory to NativeLibrary.Load, it no longer does the default search. This change propagates the tracking of whether flags were user-specified to the resolver invocation, so the resolver is given the attribute value or null for non-user-specified. Fixes #129798 ## Regression - [x] Yes - [ ] No #114756 ## Testing Automated tests added. ## Risk Low. Mono-only, propagating a boolean value correctly. Co-authored-by: Elinor Fung <[email protected]> Co-authored-by: Copilot <[email protected]>
eiriktsarpalis
pushed a commit
that referenced
this pull request
Jul 15, 2026
…no (#129831) On Mono, when no search flags are user-specified, `lookup_pinvoke_call_impl` defaults the flags to `DLLIMPORTSEARCHPATH_ASSEMBLY_DIRECTORY` for the built-in probing logic. `netcore_resolve_with_dll_import_resolver` then derived whether to report search flags to the resolver from `flags != 0`, so the explicit `AssemblyDirectory` value was passed to the resolver instead of `null`. The expected `DllImportResolver` contract is that `searchPath` is the attribute value, or `null` when neither the P/Invoke nor the assembly has the attribute. After #114756, specifying only `AssemblyDirectory` meant only assembly directory. This means that when a resolver that forwards the (wrongly non-null) `AssemblyDirectory` to `NativeLibrary.Load`, it no longer does the default search (bare `dlopen`/`LoadLibrary`). This change passes the `user_specified_flags` value through to the resolver invocation and uses it for "has search flags", so the resolver receives the attribute value or `null` for non-user-specified. Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Mono, when no search flags are user-specified,
lookup_pinvoke_call_impldefaults the flags toDLLIMPORTSEARCHPATH_ASSEMBLY_DIRECTORYfor the built-in probing logic.netcore_resolve_with_dll_import_resolverthen derived whether to report search flags to the resolver fromflags != 0, so the explicitAssemblyDirectoryvalue was passed to the resolver instead ofnull. The expectedDllImportResolvercontract is thatsearchPathis the attribute value, ornullwhen neither the P/Invoke nor the assembly has the attribute.After #114756, specifying only
AssemblyDirectorymeant only assembly directory. This means that when a resolver that forwards the (wrongly non-null)AssemblyDirectorytoNativeLibrary.Load, it no longer does the default search (baredlopen/LoadLibrary).This change passes the
user_specified_flagsvalue through to the resolver invocation and uses it for "has search flags", so the resolver receives the attribute value ornullfor non-user-specified.cc @dotnet/appmodel @AaronRobinsonMSFT
See #129798. We should backport to 10.
Note
This pull request was created with GitHub Copilot.