-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle returned GetMainProgramHandle() not sufficient for resolving statically linked native symbols on iOS #77985
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsDescriptionBased on the discussion in #57610 we were under the impression that using I created a sample native iOS library (libsayhello) and a wrapping C# lib which handles [DllImport("libsayhello')]. Then within a sample Maui app I added Interop code to allow my lib to be statically linked into the main application at compile time, then attempted to catch the resolution of 'libsayhello' in the import resolver and return the handle returned by GetMainProgramHandle(). Reproduction StepsA test app showing the behavior is located at stanger/ResolverTest. Expected behaviorDllImport calls for 'libsayhello' should be able to resolved to their statically linked symbols in the main binary. Actual behaviorDllNotFoundException Regression?No response Known WorkaroundsNo response Configuration.NET: 7.0.100-rc.2.22477.23 Other informationNo response
|
This comment was marked as outdated.
This comment was marked as outdated.
Going by: runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs Line 261 in 02c3e95
IntPtr.Zero .
|
In which case, I'm not sure what would be causing a @stranger, can you confirm what |
Hmm. In that case, I'm not sure the issue off the top of my head. Can you get the stack trace for where the exception is thrown from? I don't have a Mac handy at the moment. Also, can you try adding |
The stack trace isn't overly verbose and the inner exception was null.
I have also updated the sample lib definition with |
Tagging subscribers to 'os-ios': @steveisok, @akoeplinger Issue DetailsDescriptionBased on the discussion in #57610 we were under the impression that using I created a sample native iOS library (libsayhello) and a wrapping C# lib which handles [DllImport("libsayhello')]. Then within a sample Maui app I added Interop code to allow my lib to be statically linked into the main application at compile time, then attempted to catch the resolution of 'libsayhello' in the import resolver and return the handle returned by GetMainProgramHandle(). Reproduction StepsA test app showing the behavior is located at stanger/ResolverTest. Expected behaviorDllImport calls for 'libsayhello' should be able to resolved to their statically linked symbols in the main binary. Actual behaviorDllNotFoundException Regression?No response Known WorkaroundsNo response Configuration.NET: 7.0.100-rc.2.22477.23 Other informationNo response
|
When user-defined resolvers return self handle via `GetMainProgramHandle()`, we lookup the cached handle in mono and fail to find one because `internal_module` is not cached in `native_library_module_map`. Fix is to test the resolver returned handle against self; before the map lookup (which happens under the lock). Close #77985. * Allow interop resolvers to return self handle * Disable new test on windows and monointerpreter * Add new test to monointerpreter ExcludeList
Description
Based on the discussion in #57610 we were under the impression that using
GetMainProgramHandle()
in tandem withNativeLibrary.SetDllImportResolver()
would be a replacement for having to modify third party packages to use[DllImport("_Internal")]
on iOS. So far in testing on .NET 7 this has not been the case.I created a sample native iOS library (libsayhello) and a wrapping C# lib which handles [DllImport("libsayhello')]. Then within a sample Maui app I added Interop code to allow my lib to be statically linked into the main application at compile time, then attempted to catch the resolution of 'libsayhello' in the import resolver and return the handle returned by GetMainProgramHandle().
Reproduction Steps
A test app showing the behavior is located at stanger/ResolverTest.
Expected behavior
DllImport calls for 'libsayhello' should be able to resolved to their statically linked symbols in the main binary.
Actual behavior
DllNotFoundException
Regression?
No response
Known Workarounds
No response
Configuration
.NET: 7.0.100-rc.2.22477.23
iOS 16 and MacOS 13 (originally discovered on iOS)
Tested on x64 and ARM64
Other information
No response
The text was updated successfully, but these errors were encountered: