You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native Library loading IOS Frameworks in .NET 10 #129798
Before I go and update about 5 different projects and begin a cycle of dependency updates, I want to ask whether this is really intended behaviour?
Steps to Reproduce
I was going to provide some steps here, but I'm uncovering even more issues that makes this very annoying to create a reproduction for. It's just a question anyway.
Loading an embedded iOS native framework via NativeLibrary.Load("@rpath/<Name>.framework/<Name>", assembly, searchPath) from a DllImportResolver worked on .NET 8/9 but throws DllNotFoundException on .NET 10.
The root cause is not in dlopen or in dyld's @rpath resolution. dlopen is still
called and dyld still resolves @rpath correctly. The regression is in CoreCLR's managed
native-library search algorithm (coreclr/vm/nativelibrary.cpp, LoadNativeLibraryBySearch): for the default / AssemblyDirectory search semantics it no
longer hands the raw "@rpath/…" string to dlopen, so dyld never gets a chance to resolve it.
A self-contained reproduction was built in /Users/rolf/test/bugs/issue25792:
native/mynative.c — one function int my_native_add(int, int).
native/build-framework.sh — builds a fat (x86_64 + arm64) iOS-simulator MyNative.framework whose install name is @rpath/MyNative.framework/MyNative (exactly like
the real-world SDL3 / veldrid-spirv / realm frameworks in the issue).
ReproApp/ — a net10.0-ios app that embeds the framework via:
macios embeds it at ReproApp.app/Frameworks/MyNative.framework/MyNative and adds an @executable_path/Frameworks LC_RPATH, so @rpath/MyNative.framework/MyNative resolves to the
embedded framework.
ReproApp/NativeRepro.cs — runs probes A–F at startup (from AppDelegate.FinishedLaunching).
Environment: macOS (Intel/x86_64 host), .NET SDK 10.0.107, Microsoft.iOS workload
26.2.10233/10.0.100, iPhone 15 Pro simulator (iOS 26.2). Built with dotnet build -c Debug -r iossimulator-x64, installed/launched with simctl, output captured
from the unified log.
raw dlopen("@rpath/MyNative.framework/MyNative", RTLD_NOW)
SUCCESS
(F)
raw dlopen("<app>/Frameworks/MyNative.framework/MyNative")
SUCCESS
(A) is the exact .NET 8/9 pattern — it regressed on .NET 10.
(E) is decisive: the OS loader resolves @rpath fine. dlopen/dyld are not the problem.
Mechanism (code walk-through)
Relevant function: LoadNativeLibraryBySearch in src/coreclr/vm/nativelibrary.cpp
(release/10.0). On Apple/Unix, LocalLoadLibraryHelper(name) → PAL_LoadLibraryDirect(name) → dlopen(name, RTLD_LAZY).
For libName = "@rpath/MyNative.framework/MyNative":
libNameIsRelativePath = Path::IsRelative(libName) is true — the string does not start
with /. (dyld's @rpath/@executable_path/@loader_path prefixes are not understood by
CoreCLR's path classifier; they are treated as ordinary relative paths.)
For each name variation the loop tries, in order:
a. LoadFromNativeDllSearchDirectories(name) — prepends every NATIVE_DLL_SEARCH_DIRECTORIES entry: dlopen("<dir>/@rpath/MyNative.framework/MyNative").
These are nonsensical paths (a literal @rpath path segment) and always fail.
b. if (!libNameIsRelativePath) { LocalLoadLibraryHelper(name, …) } — a bare dlopen("@rpath/…"). Skipped here because the name is classified as relative.
c. else if (callingAssembly != nullptr && searchAssemblyDirectory)
→ LoadFromPInvokeAssemblyDirectory(...): dlopen("<assemblyDir>/@rpath/…") — for a
bundled iOS assembly the assembly directory is the .app bundle dir, so this is again a
nonsensical concatenated path and fails.
d. Final fallback:
if (!userSpecifiedSearchFlags || !searchAssemblyDirectory || dllImportSearchPathFlags != 0)
hmod = LocalLoadLibraryHelper(currLibNameVariation, dllImportSearchPathFlags); // bare dlopen("@rpath/…")
This bare dlopen("@rpath/…") is the only attempt that lets dyld resolve @rpath
(proven by probe E). Whether it runs depends entirely on the gate.
Evaluating the gate:
Default P/Invoke semantics / AssemblyDirectory: userSpecifiedSearchFlags == true, searchAssemblyDirectory == true, dllImportSearchPathFlags == 0 → gate is false →
bare dlopen is skipped → DllNotFoundException. This is probes (A) and (C).
ApplicationDirectory: maps to a non-zerodllImportSearchPathFlags (it is not the
assembly-directory bit) → dllImportSearchPathFlags != 0 → gate is true → bare dlopen("@rpath/…") runs → dyld resolves it → SUCCESS. This is probe (B).
The single-argument NativeLibrary.Load(path) (probe D) bypasses the search entirely:
it is a direct LocalLoadLibraryHelper(path, LOAD_WITH_ALTERED_SEARCH_PATH) = a bare dlopen, so it also succeeds.
Key takeaways
dlopen is still called. It is not bypassed, and dyld's @rpath handling is intact.
The regression is that CoreCLR feeds dlopendirectory-prefixed variants
(<dir>/@rpath/…, which can never succeed) and skips the one bare-string dlopen call
that dyld could resolve — unless a non-AssemblyDirectory search flag is set.
DllImportSearchPath.ApplicationDirectory "fixes" it only as a side effect of changing
control flow (it makes dllImportSearchPathFlags != 0), not because it points anywhere near
the framework. Any code relying on this is relying on a fallthrough, not on documented
ApplicationDirectory semantics.
The PR's stated change: stop always adding the app directory (and single-file extraction
directory) to NATIVE_DLL_SEARCH_DIRECTORIES, and treat a bundled assembly's directory as the
bundle/app directory. iOS apps are single-file/bundled, so they are directly affected.
Relevant hunks:
hostpolicy/deps_resolver.cpp: removed the block that, for single-file bundles, added bundle->base_path() (and the extraction path) to the native search directories.
vm/nativelibrary.cppLoadFromPInvokeAssemblyDirectory: now resolves a bundled assembly's
path to the bundle path (previously empty → early return NULL).
On .NET 8/9 the bundle/app directory was always present in the probe list and the control flow
reached the bare-string dlopen, so the @rpath/… form resolved. The .NET 10 changes shifted
that flow so the default / AssemblyDirectory path no longer reaches the bare dlopen,
producing the regression.
Recommended fixes / workarounds for app authors
Documented workaround: OR-in DllImportSearchPath.ApplicationDirectory in the resolver:
Equivalent alternative: use the single-argument NativeLibrary.Load("@rpath/Foo.framework/Foo")
(direct dlopen).
Or load by resolved absolute path: Path.Combine(AppContext.BaseDirectory, "Frameworks/Foo.framework/Foo") (probe F).
Whether the .NET 10 behavior is intended for Apple platforms (where @rpath/@loader_path
are first-class loader concepts, unlike on Linux) is the open question raised in the issue.
TLDR; it seems NativeLibrary.Load ("@rpath/...", assembly) will prepend search paths, end up trying to load non-sensical paths like "/search/path@rpath/...").
This seems like an issue in dotnet/runtime, so I'm moving this issue there. IMHO "@rpath/..." paths should be treated like absolute paths and loaded as-is without prepending any search paths.
As a workaround, the simplest solution is to call NativeLibrary.Load ("@rpath/..") (i.e. no second assembly argument).
This is a regression from https://learn.microsoft.com/dotnet/core/compatibility/interop/10.0/native-library-search (#114756). This specifically affects Mono resolving via DllImportResolver with default search path behaviour (so no DllImportSearchPath specified on the p/invoke or the assembly). When calling the DllImportResolver when no search paths were explicitly specified, Mono passes DllImportSearchPath.AssemblyDirectory instead of null - #114756 missed updating that. That means the NativeLibrary.Load("...", assembly, path) call in your resolver ends up having only DllImportSearchPath.AssemblyDirectory specified and we don't do the default load.
Before I go and update about 5 different projects and begin a cycle of dependency updates, I want to ask whether this is really intended behaviour?
Decidedly not intended. Thanks for reporting this.
@MichaelLHerman the fix from #129862 shipped with 10.0.11 of the runtime which was released a short while ago. You should be able to get it by updating to the latest version.
Activity
rolfbjarne commentedon Jun 24, 2026
Thanks for the report!
I can reproduce, here's a sample app: ReproApp-6b5f1fa.zip
Copilot's analysis
Analysis: #129798 — native framework
@rpathloading broken in .NET 10Summary
Loading an embedded iOS native framework via
NativeLibrary.Load("@rpath/<Name>.framework/<Name>", assembly, searchPath)from aDllImportResolverworked on .NET 8/9 but throwsDllNotFoundExceptionon .NET 10.The root cause is not in
dlopenor in dyld's@rpathresolution.dlopenis stillcalled and dyld still resolves
@rpathcorrectly. The regression is in CoreCLR's managednative-library search algorithm (
coreclr/vm/nativelibrary.cpp,LoadNativeLibraryBySearch): for the default /AssemblyDirectorysearch semantics it nolonger hands the raw
"@rpath/…"string todlopen, so dyld never gets a chance to resolve it.Related:
("Remove always searching executable directory for native libraries in single-file applications")
Reproduction
A self-contained reproduction was built in
/Users/rolf/test/bugs/issue25792:native/mynative.c— one functionint my_native_add(int, int).native/build-framework.sh— builds a fat (x86_64 + arm64) iOS-simulatorMyNative.frameworkwhose install name is@rpath/MyNative.framework/MyNative(exactly likethe real-world SDL3 / veldrid-spirv / realm frameworks in the issue).
ReproApp/— anet10.0-iosapp that embeds the framework via:ReproApp.app/Frameworks/MyNative.framework/MyNativeand adds an@executable_path/FrameworksLC_RPATH, so@rpath/MyNative.framework/MyNativeresolves to theembedded framework.
ReproApp/NativeRepro.cs— runs probes A–F at startup (fromAppDelegate.FinishedLaunching).Environment: macOS (Intel/x86_64 host), .NET SDK 10.0.107, Microsoft.iOS workload
26.2.10233/10.0.100, iPhone 15 Pro simulator (iOS 26.2). Built with
dotnet build -c Debug -r iossimulator-x64, installed/launched withsimctl, output capturedfrom the unified log.
Measured results (on-device, iOS simulator, .NET 10)
NativeLibrary.Load("@rpath/…", asm, searchPath)(resolver)DllNotFoundExceptionNativeLibrary.Load("@rpath/…", asm, ApplicationDirectory)NativeLibrary.Load("@rpath/…", asm, AssemblyDirectory)DllNotFoundExceptionNativeLibrary.Load("@rpath/…")(single-arg, direct)dlopen("@rpath/MyNative.framework/MyNative", RTLD_NOW)dlopen("<app>/Frameworks/MyNative.framework/MyNative")@rpathfine. dlopen/dyld are not the problem.Mechanism (code walk-through)
Relevant function:
LoadNativeLibraryBySearchinsrc/coreclr/vm/nativelibrary.cpp(release/10.0). On Apple/Unix,
LocalLoadLibraryHelper(name)→PAL_LoadLibraryDirect(name)→dlopen(name, RTLD_LAZY).For
libName = "@rpath/MyNative.framework/MyNative":libNameIsRelativePath = Path::IsRelative(libName)is true — the string does not startwith
/. (dyld's@rpath/@executable_path/@loader_pathprefixes are not understood byCoreCLR's path classifier; they are treated as ordinary relative paths.)
For each name variation the loop tries, in order:
a.
LoadFromNativeDllSearchDirectories(name)— prepends everyNATIVE_DLL_SEARCH_DIRECTORIESentry:dlopen("<dir>/@rpath/MyNative.framework/MyNative").These are nonsensical paths (a literal
@rpathpath segment) and always fail.b.
if (!libNameIsRelativePath) { LocalLoadLibraryHelper(name, …) }— a baredlopen("@rpath/…"). Skipped here because the name is classified as relative.c.
else if (callingAssembly != nullptr && searchAssemblyDirectory)→
LoadFromPInvokeAssemblyDirectory(...):dlopen("<assemblyDir>/@rpath/…")— for abundled iOS assembly the assembly directory is the
.appbundle dir, so this is again anonsensical concatenated path and fails.
d. Final fallback:
This bare
dlopen("@rpath/…")is the only attempt that lets dyld resolve@rpath(proven by probe E). Whether it runs depends entirely on the gate.
Evaluating the gate:
AssemblyDirectory:userSpecifiedSearchFlags == true,searchAssemblyDirectory == true,dllImportSearchPathFlags == 0→ gate is false →bare
dlopenis skipped →DllNotFoundException. This is probes (A) and (C).ApplicationDirectory: maps to a non-zerodllImportSearchPathFlags(it is not theassembly-directory bit) →
dllImportSearchPathFlags != 0→ gate is true → baredlopen("@rpath/…")runs → dyld resolves it → SUCCESS. This is probe (B).The single-argument
NativeLibrary.Load(path)(probe D) bypasses the search entirely:it is a direct
LocalLoadLibraryHelper(path, LOAD_WITH_ALTERED_SEARCH_PATH)= a baredlopen, so it also succeeds.Key takeaways
@rpathhandling is intact.dlopendirectory-prefixed variants(
<dir>/@rpath/…, which can never succeed) and skips the one bare-stringdlopencallthat dyld could resolve — unless a non-AssemblyDirectory search flag is set.
DllImportSearchPath.ApplicationDirectory"fixes" it only as a side effect of changingcontrol flow (it makes
dllImportSearchPathFlags != 0), not because it points anywhere nearthe framework. Any code relying on this is relying on a fallthrough, not on documented
ApplicationDirectory semantics.
Tie-in to #115236
The PR's stated change: stop always adding the app directory (and single-file extraction
directory) to
NATIVE_DLL_SEARCH_DIRECTORIES, and treat a bundled assembly's directory as thebundle/app directory. iOS apps are single-file/bundled, so they are directly affected.
Relevant hunks:
hostpolicy/deps_resolver.cpp: removed the block that, for single-file bundles, addedbundle->base_path()(and the extraction path) to the native search directories.vm/nativelibrary.cppLoadFromPInvokeAssemblyDirectory: now resolves a bundled assembly'spath to the bundle path (previously empty → early
return NULL).On .NET 8/9 the bundle/app directory was always present in the probe list and the control flow
reached the bare-string
dlopen, so the@rpath/…form resolved. The .NET 10 changes shiftedthat flow so the default /
AssemblyDirectorypath no longer reaches the baredlopen,producing the regression.
Recommended fixes / workarounds for app authors
DllImportSearchPath.ApplicationDirectoryin the resolver:NativeLibrary.Load("@rpath/Foo.framework/Foo")(direct
dlopen).Path.Combine(AppContext.BaseDirectory, "Frameworks/Foo.framework/Foo")(probe F).Whether the .NET 10 behavior is intended for Apple platforms (where
@rpath/@loader_pathare first-class loader concepts, unlike on Linux) is the open question raised in the issue.
TLDR; it seems
NativeLibrary.Load ("@rpath/...", assembly)will prepend search paths, end up trying to load non-sensical paths like "/search/path@rpath/...").This seems like an issue in dotnet/runtime, so I'm moving this issue there. IMHO "@rpath/..." paths should be treated like absolute paths and loaded as-is without prepending any search paths.
As a workaround, the simplest solution is to call
NativeLibrary.Load ("@rpath/..")(i.e. no second assembly argument).dotnet-policy-service commentedon Jun 24, 2026
Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Jun 24, 2026
Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.
AaronRobinsonMSFT commentedon Jun 24, 2026
@elinor-fung Can you please confirm our intent here.
elinor-fung commentedon Jun 24, 2026
This is a regression from https://learn.microsoft.com/dotnet/core/compatibility/interop/10.0/native-library-search (#114756). This specifically affects Mono resolving via DllImportResolver with default search path behaviour (so no
DllImportSearchPathspecified on the p/invoke or the assembly). When calling the DllImportResolver when no search paths were explicitly specified, Mono passesDllImportSearchPath.AssemblyDirectoryinstead ofnull- #114756 missed updating that. That means theNativeLibrary.Load("...", assembly, path)call in your resolver ends up having onlyDllImportSearchPath.AssemblyDirectoryspecified and we don't do the default load.Decidedly not intended. Thanks for reporting this.
[release/10.0] Pass correct search path to DllImportResolver for defa…
MichaelLHerman commentedon Aug 20, 2026
which release version of .NET MAUI will have the runtime with the fix? Is this fixed in MAUI 10.0.100?
akoeplinger commentedon Aug 21, 2026
@MichaelLHerman the fix from #129862 shipped with 10.0.11 of the runtime which was released a short while ago. You should be able to get it by updating to the latest version.