Skip to content
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

Release mode on iOS causes DllNotFoundException #22223

Open
borrrden opened this issue Feb 21, 2025 · 6 comments
Open

Release mode on iOS causes DllNotFoundException #22223

borrrden opened this issue Feb 21, 2025 · 6 comments
Labels
need-attention An issue requires our attention/response
Milestone

Comments

@borrrden
Copy link

Apple platform

iOS

Framework version

net8.0-*

Affected platform version

dotnet CLI 9.0.102

Description

This is a sort of resurrection of #21594

The issue is that when building Debug, things work fine. When building with default Release configuration a DllNotFoundException happens. A nuget package is providing a native ios framework for use via P/Invoke, and this is where the exception happens. The native library is in fact present in both .app bundles (debug and release). Furthermore, turning on MtouchInterpreter for the .NET assembly that comes with the native framework also seems to make the problem go away. This only happens on an actual device. The simulator is unaffected.

I am the developer of the library in question, and a reproduction repo was provided by a third party that uses our library.

Steps to Reproduce

  1. Clone the following repo https://github.com/tele-bird/CouchbaseLiteExample
  2. Checkout commit c54380f20dc70b218750e092e1945b34b06f5d21 (HEAD - 1)
  3. Change the bundle ID in both the csproj and info.plist to something that you have a provisioning profile for
  4. Build the app for release on device dotnet build -f net8.0-ios -c:Release -p:RuntimeIdentifier=ios-arm64
  5. Install the app onto an iOS device and click the "Click Me" button
  6. Observe the difference in output text between the debug and release configuration

Did you find any workaround?

Adding MtouchInterpreter on the assembly Couchbase.Lite.Enterprise.Support.iOS as done in tele-bird/CouchbaseLiteExample@443bd5b

Relevant logs

No response

@borrrden
Copy link
Author

Some additional information that I didn't think to include originally. I use DllImportResolver as follows to redirect "LiteCore" to its equivalent rpath location within the framework:

https://github.com/couchbase/couchbase-lite-net/blob/3.2.1/src/LiteCore/src/LiteCore.Shared/Interop/NativeActivate.cs#L21-L23

It uses the const string DllName as input https://github.com/couchbase/couchbase-lite-net/blob/3.2.1/src/LiteCore/src/LiteCore.Shared/Constants.cs#L24

The DllName is then on each of the P/Invoke entries. In this case the likely culprit is the following line:

https://github.com/couchbase/couchbase-lite-net/blob/3.2.1/src/Couchbase.Lite.Shared/API/Log/FileLogger.cs#L231

which calls to a P/Invoke function

https://github.com/couchbase/couchbase-lite-net/blob/3.2.1/src/LiteCore/src/LiteCore.Shared/Interop/Misc_native.cs#L29

@rolfbjarne
Copy link
Member

This is probably a duplicate of #19624.

Can you try some of the suggestions in that issue to see if that works around the problem?

@rolfbjarne rolfbjarne added the need-info Waiting for more information before the bug can be investigated label Feb 21, 2025
@rolfbjarne rolfbjarne added this to the Future milestone Feb 21, 2025
@borrrden
Copy link
Author

The exception thrown in that issue is different from what I am seeing, but are you suggesting perhaps that the dead link strip is simply just causing the entire library to be ignored?

@dotnet-policy-service dotnet-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Feb 21, 2025
@borrrden
Copy link
Author

I also noticed that the linked issue is using a static lib. This is a dynamically linked framework if that makes a difference.

@borrrden
Copy link
Author

I tried the three workarounds mentioned in the other ticket. The dlsym one didn't work because I realize I have DllImport functions that are not exercised at runtime but are still defined inappropriately outside of a Windows context (the ticket warned that this would fail if that was the case). The other two had no effect.

@borrrden
Copy link
Author

borrrden commented Feb 21, 2025

For some additional info, I attached a build.log from a release build

Some lines of note:

       _LinkNativeExecutable:
         Tool xcrun execution started with arguments: clang++ -F /Users/jim.borden/Development/CouchbaseLiteExample/MauiApp1/obj/Release/net8.0-ios/ios-arm64/LiteCore.xcframework.zip/LiteCore.xcframework/ios-arm64 -framework LiteCore -mios-version-min=11.0 -isysroot /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk -arch arm64 <long list of AOT compiled objects...> -framework CFNetwork -framework CloudKit -framework Contacts -framework ContactsUI -framework CoreFoundation -framework CoreGraphics -framework CoreImage -framework CoreLocation -framework CoreText -framework Foundation -framework ImageIO -framework Intents -framework MediaPlayer -framework QuartzCore -framework SafariServices -framework Security -framework SystemConfiguration -framework UIKit -framework WebKit -weak_framework AuthenticationServices -weak_framework LinkPresentation -framework GSS -framework CFNetwork -framework Security -rpath @executable_path/Frameworks /Users/jim.borden/Development/CouchbaseLiteExample/MauiApp1/obj/Release/net8.0-ios/ios-arm64/nativelibraries/main.arm64.o /Users/jim.borden/Development/CouchbaseLiteExample/MauiApp1/obj/Release/net8.0-ios/ios-arm64/nativelibraries/registrar.o -o /Users/jim.borden/Development/CouchbaseLiteExample/MauiApp1/obj/Release/net8.0-ios/ios-arm64/nativelibraries/MauiApp1 -dead_strip -lz -liconv -lcompression -lobjc <long list of -u arguments...>
_CopyDirectoriesToBundle:
         /usr/bin/ditto /Users/jim.borden/Development/CouchbaseLiteExample/MauiApp1/obj/Release/net8.0-ios/ios-arm64/LiteCore.xcframework.zip/LiteCore.xcframework/ios-arm64/LiteCore.framework/ /Users/jim.borden/Development/CouchbaseLiteExample/MauiApp1/bin/Release/net8.0-ios/ios-arm64/MauiApp1.app/Frameworks/LiteCore.framework --arch arm64 
_CodesignAppBundle:
         Tool /usr/bin/codesign execution started with arguments: -v --force --timestamp=none --sign 577294CE08B43E368F332FFA35B5AD2101546BA2 /Users/jim.borden/Development/CouchbaseLiteExample/MauiApp1/bin/Release/net8.0-ios/ios-arm64/MauiApp1.app/Frameworks/LiteCore.framework

build.log

@drasticactions drasticactions marked this as a duplicate of dotnet/maui#27944 Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-attention An issue requires our attention/response
Projects
None yet
Development

No branches or pull requests

2 participants