Unexpected characters in Trampoline.g.cs and SupportDelegate.g.cs due to nested Action objects

EladNavaEladNava Elad NavaUS

Hi there,
I'm experiencing a very strange scenario with my AppDelegate.cs.

Objective Sharpie generated the following method declaration:

// -(void)setNotificationHandler:(void (^ _Nonnull)(NSDictionary * _Nonnull, void (^ _Nonnull)(UIBackgroundFetchResult)))notificationHandler;
        [Export ("setNotificationHandler:")]    
        void SetNotificationHandler(Action<NSDictionary, Action<UIBackgroundFetchResult>> notificationHandler);

As you can see, the parameter is an action with a nested action objects.

When building the iOS binding library project, weird symbols are inserted into both Trampoline.g.cs and SupportDelegate.g.cs, causing the following errors:

Line 63 of Trampoline.g.cs:

                    del ( Runtime.GetNSObject<NSDictionary> (arg1), (System.Action`1[UIKit.UIBackgroundFetchResult]) Marshal.GetDelegateForFunctionPointer (arg2, typeof (System.Action`1[UIKit.UIBackgroundFetchResult])));

Contents of SupportDelegate.g.cs:

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

If I manually change the declaration in AppDelegate.cs to the following

    void SetNotificationHandler(Action<NSDictionary, Action> notificationHandler);

Then the project compiles, however, this is invalid as the project will fail at runtime when the notification handler is actually called from the native code.

Does anyone know how to overcome this?



  • EladNavaEladNava Elad Nava US
    edited March 12

    I ended up working around this, simply removing the Action parameters. It seems the current version of Xamarin has trouble calling native actions from C# code.

Sign In or Register to comment.