Error: Attempting to JIT compile method

I’m running a piece of code that opens a db, then fires up the sync engine. On the iOS simulator it works, on the Mac it works and on iOS it doesn’t work, although it worked prior to the 3.1.0 release.

The error in iOS seems to be raised just after my replication change listener callback has completed, after being called with the ReplicatorActivityLevel.Connecting state. This is the error message:

Attempting to JIT compile method '(wrapper managed-to-native) intptr Couchbase.Lite.Support.IOSProxy/CFNetworkCopySystemProxySettings:wrapper_aot_native (object)' while running in aot-only mode. See for more information.

Reviewing the forum history, I did find the previous occurrence of the above error here.

In that topic, i found the following comment from @borrrden:

Oh dear, this is a classic case of forgotten callback attribute on a method that is called from unmanaged code. That’s a bug on the Couchbase side.

Is it possible the same problem has resurfaced, or is this something new?

Some Details:
Hardware/OS: MacOS ventura, iOS 16.4.1, .Net 7, .Net for iOS.

Replication Configuration:

            var url = new Uri(config.sync_url);
            var target = new URLEndpoint(url);
            var auth = new BasicAuthenticator(id, GetServerPassword());
            var sync_config = new ReplicatorConfiguration(database, target)
                ReplicatorType = ReplicatorType.PushAndPull,
                Continuous = true,
                Authenticator = auth,
                ConflictResolver = new SyncConflictResolver(),
            replicator = new Replicator(sync_config);
            listenerToken = replicator.AddChangeListener(SyncStatusUpdate);


Thank you.

This actually looks like the exact INVERSE of that problem. Note the “wrapped managed-to-native” which I believe, at first glance, means it is somehow missing some glue between .NET and the underlying C call. The mac implementation was copied to be used on iOS, and it does make use of some dynamic calling so it could be that Marshal.GetDelegate is returning something that fails to be considered in AOT. It seems like this will only happen if a proxy is being used. Is that the case here? Otherwise it would have shown up in our testing.

According to this we need to mark the actual delegates as native interop, which we failed to do. That might explain things. I will file a bug report on this.

1 Like

It seems like this will only happen if a proxy is being used. Is that the case here?

There is no proxy involved.

It’s weird that we haven’t seen it then. We do all kinds of replication testing on iOS devices and I haven’t heard of any incidents. Regardless, I know why it happens (I think) but I don’t know why it doesn’t happen for me…

3.0.8 still continues to work for iOS 16.4.1 though? The entire reason for the change that caused this was because the CFNetwork library path changed in macOS 13. If it remains the same in iOS 16 then the fix can simply be backing out this change and using the old hardcoded (DllImport) variant for iOS. Mac Catalyst might be an issue though, not sure about that.

I pushed the needed attributes to a branch called fix/cbl-4505_ios_proxy. If you are familiar with building the library then the result will be a drop in replacement for 3.1.0 with (hopefully) the issue solved. This is assuming CE though, EE is another story and will require a support ticket.

3.0.8 still continues to work for iOS 16.4.1 though?

One of the first things I did was trying 3.0.8, but Couchbase.Lite.Support.iOS does not seem to be compatible with net7:

Package Couchbase.Lite.Support.iOS 3.0.8 is not compatible with net7.0-ios16.2 (.NETCoreApp,Version=v7.0). Package Couchbase.Lite.Support.iOS 3.0.8 supports: xamarinios (Xamarin.iOS,Version=v0.0)

Have the dependencies changed?

3.1.0 was the first version to be .NET 6+ compatible, but I thought you were using Xamarin before since you indicated that things were working at a previous point in time. Unfortunately Microsoft did not migrate Xamarin directly to .NET 6 so they are not compatible.

Couchbase.Lite main package (important edit: Prior to 3.1.0) will only give the illusion that it works, because it has a .NET Standard 2.0 slice that was meant for packages which only have a transient dependency on Couchbase (i.e. the package is a .NET standard package that depends on Couchbase). It doesn’t actually function on .NET 6.

Yeah - I was using Xamarin (you have a good memory), but just ran into too many issues with CBL. Migrated to .Net 7, and “.net for iOS” (not MAUI - not all required controls are available and I don’t want to rewrite) and with the exception of iOS sync, everything is working.

Cross platform UI’s with C# are a world of frustration - WPF, WinForms, Xamarin, Xamarin.Forms, MAUI/.Net for iOS. Each is a rewrite.

Cross platforms UIs in general can have that effect. Making a unified toolchain that supports that vastly differing universes is an exercise in insanity most of the time. That being said, I think the fixes I put on the branch will be what you need, and they will be in the next 3.1.x release, and are available for your own build immediately if you desire. MAUI not required :smiley: .

In the meantime I have reproduced this and have a theory as to why I didn’t see it, but confirmed that the branch does indeed address this.

1 Like

@borrrden Sorry to bug you. I thought I’d wait for the next official release that included the above fix… but its been 7 weeks. To move forward, I need to build the library, but I can’t find the branch you mention above (fix/cbl-4505_ios_proxy). It doesn’t exist on the couchbase-lite-ios or couchbase-lite-net that I can find.

Is there a document available on how to do this?

Many thanks.

The branch was deleted since it was merged into the release branch (release/3.1). You can use the release branch if you wish (CBL-4505: Add attributes to iOS proxy unmanaged delegates by borrrden · Pull Request #1522 · couchbase/couchbase-lite-net · GitHub notes this flow). Regarding the release, I just moments ago put out an RC2 internally, so it’s nearing release.