Search code examples
xamarinxamarin.iosxamarin.ios-binding

Binding iOS Framework leads to corrupted temporary files


I have a pretty massive iOS Framework to bind. This framework depends on two others.

I created the binding project, successfully generated the ApiDefinitions.cs file and StructsAndEnums.cs. So far so good.

Now, when I try to build it in Debug mode, I get about 30+ errors regarding syntax issues in temporary files.

These errors only occur in Trampolines.g.cs, and SupportDelegates.g.cs files. The worst of the two is the SupportDelegates.g.cs file which looks like this :

   //
// Auto-generated from generator.cs, do not edit
//
// We keep references to objects, so warning 414 is expected

#pragma warning disable 414

using System;
using System.Drawing;
using System.Diagnostics;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using UIKit;
using GLKit;
using Metal;
using MapKit;
using Photos;
using ModelIO;
using SceneKit;
using Contacts;
using Security;
using Messages;
using AudioUnit;
using CoreVideo;
using CoreMedia;
using QuickLook;
using CoreImage;
using SpriteKit;
using Foundation;
using CoreMotion;
using ObjCRuntime;
using AddressBook;
using MediaPlayer;
using GameplayKit;
using CoreGraphics;
using CoreLocation;
using AVFoundation;
using NewsstandKit;
using FileProvider;
using CoreAnimation;
using CoreFoundation;

namespace System.Action`1[[Foundation.NSString, Xamarin.iOS, Version=0.0.0 {
    public delegate void 0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]] (NSString obj);
}

The Trampolines.g.cs file is generating almost completely, but the same kind of issue appears in the middle of the generated C# code:

static internal class SDActionArity2V1 {
            static internal readonly DActionArity2V1 Handler = Invoke;

            [MonoPInvokeCallback (typeof (DActionArity2V1))]
            static unsafe void Invoke (IntPtr block, IntPtr arg1, IntPtr arg2) {
                var descriptor = (BlockLiteral *) block;
                var del = (global::System.Action<NSString, global::System.Action<NSString>>) (descriptor->Target);
                if (del != null)
                    del ( Runtime.GetNSObject<NSString> (arg1), (System.Action`1[Foundation.NSString]) Marshal.GetDelegateForFunctionPointer (arg2, typeof (System.Action`1[Foundation.NSString])));
            }
        }

Some other binding projects is generating the same kind of files, and eveything seems to be working fine, so I'm actually struggling to find the root cause of this.

Any ideas ?

EDIT: To give more infos here is the generated interface definition https://gist.github.com/Miiite/367e17335431e932acdc92c65b504bd4

EDIT2: Here is what sharpie generated as log output https://gist.github.com/Miiite/e272622df2e853d53f1add4c8eb4eabf


Solution

  • I believe the issue is here: void PresentCheckoutForSubmittingTransactionCompletionHandler(Action<OPPTransaction, NSError> completionHandler, [NullAllowed] Action<NSString, Action<NSString>> paymentBrandSelectedHandler, [NullAllowed] Action cancelHandler);

    I think the Action inside the Action is causing the problem, the generator might not support this, so you might need to find a different way of binding that.