xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.47k stars 513 forks source link

Attempting to JIT compile method '(wrapper managed-to-native) #4021

Closed wescur88 closed 6 years ago

wescur88 commented 6 years ago

Steps to Reproduce

  1. Create a binding that uses Marshal.GetDelegateForFunctionPointer
  2. Add [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)] attribute to delegate.

Expected Behavior

Return a native delegate

Actual Behavior

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) MTBeaconPlusBinding.MTPasswordBlock:wrapper_aot_native (object,string)' while running in aot-only mode. See https://developer.xamarin.com/guides/ios/advanced_topics/limitations/ for more information.

Environment

Visual Studio 2017 Professional

Microsoft Visual Studio Professional 2017 
Version 15.6.6
VisualStudio.15.Release/15.6.6+27428.2037
Microsoft .NET Framework
Version 4.7.02556

Installed Version: Professional

Visual C++ 2017   00369-60000-00001-AA413
Microsoft Visual C++ 2017

Visual F# Tools 10.1 for F# 4.1   00369-60000-00001-AA413
Microsoft Visual F# Tools 10.1 for F# 4.1

Application Insights Tools for Visual Studio Package   8.11.10402.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.0.40314.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services   1.0
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017   5.2.51214.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   15.0.40215.0
Azure App Service Tools v3.0.0

C# Tools   2.7.0-beta3-62715-05. Commit Hash: db02128e6e3c4bdfc93e6ec425ac9162b4d4fe80
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter   15.6.18072.2
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

JavaScript UWP Project System   2.0
JavaScript UWP Project System

Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.51212.2

Microsoft Continuous Delivery Tools for Visual Studio   0.3
Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   4.9.11-pre (71eb098)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Python   15.6.18072.2
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Django support   15.6.18072.2
Provides templates and integration for the Django web framework.

Python - IronPython support   15.6.18072.2
Provides templates and integration for IronPython-based projects.

Python - Profiling support   15.6.18072.2
Profiling support for Python projects.

SQL Server Data Tools   15.1.61801.210
Microsoft SQL Server Data Tools

Telerik ASP.NET AJAX VSExtensions   2017.3.1017.0
Progress® Telerik® UI for ASP.NET AJAX Visual Studio extensions

Telerik ASP.NET Core VSExtensions   2017.3.1121.0
Progress® Telerik® UI for ASP.NET Core Visual Studio extensions

Telerik ASP.NET MVC VSExtensions   2017.3.1121.0
Progress® Telerik® UI for ASP.NET MVC Visual Studio extensions

Telerik WinForms Converter   2017.3.1017.0
Progress® Telerik® UI for WinForms Converter Visual Studio extensions

Telerik WinForms VSExtensions   2018.1.215.2
Progress® Telerik® UI for WinForms Visual Studio extensions

Telerik WPF VSExtensions   2018.1.215.2
Progress® Telerik® UI for WPF Visual Studio extensions

Telerik Xamarin VSExtensions   2018.1.322.3
Progress® Telerik® UI for Xamarin Visual Studio extensions

TypeScript Tools   15.6.20202.3
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   2.7.0-beta3-62715-05. Commit Hash: db02128e6e3c4bdfc93e6ec425ac9162b4d4fe80
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Apache Cordova   15.123.7102.2
Visual Studio Tools for Apache Cordova

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Visual Studio Tools for Universal Windows Apps   15.0.27428.01
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   4.9.0.753 (f0f46392f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   4.10.96 (a702a9ceb)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK   8.2.0.16 (HEAD/a78295902)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   11.9.1.24 (f62de47)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

Example Project (If Possible)

VincentDondain commented 6 years ago

Hi,

Could you provide us with a small test case to reproduce this issue?

wescur88 commented 6 years ago

MTBeaconPlusBinding.zip

wescur88 commented 6 years ago

[iOS]BeaconPlus x86&ARM 2018.04.08 06_56PM.zip

wescur88 commented 6 years ago

using System; using System.Collections.Generic; using System.Linq; using CoreLocation; using Foundation; using MTBeaconPlusBinding; using RhythmBeacon.iOS; using Xamarin.Forms;

[assembly: Dependency(typeof(iBeacon))] namespace RhythmBeacon.iOS { public class iBeacon : IiBeacon, IDisposable { CLLocationManager locationMgr = new CLLocationManager(); CLBeaconRegion region = new CLBeaconRegion(new NSUuid("FDA50693-A4E2-4FB1-AFCF-C6EB07647825"), "com.enovate.rtls");

    MTCentralManager mtManager = null;

    List<KeyValuePair<Beacon, MTPeripheral>> beaconPeriphList = new List<KeyValuePair<Beacon, MTPeripheral>>();

    public bool IsScanning { get; set; } = false;
    public event EventHandler BeaconRanged;

    public iBeacon()
    {
        locationMgr.RequestWhenInUseAuthorization();
        locationMgr.DidRangeBeacons += LocationMgr_DidRangeBeacons;
        locationMgr.RangingBeaconsDidFailForRegion += LocationMgr_RangingBeaconsDidFailForRegion;

        mtManager = MTCentralManager.SharedInstance();          

    }

    private void LocationMgr_RangingBeaconsDidFailForRegion(object sender, CLRegionBeaconsFailedEventArgs e)
    {

    }

    private void LocationMgr_DidRangeBeacons(object sender, CLRegionBeaconsRangedEventArgs e)
    {
        BeaconRanged?.Invoke(this, new BeaconsRangededArgs(e.Beacons, Device.RuntimePlatform));
    }

    ~iBeacon()
    {
        locationMgr = null;
        region = null;          
    }

    public void StartScan()
    {
        //locationMgr.StartMonitoring(region);
        //locationMgr.StartRangingBeacons(region);
        IsScanning = true;

        mtManager.StartScan((periperials)=> {
            BeaconRanged?.Invoke(this, new BeaconsRangededArgs(periperials, Device.RuntimePlatform));
        });
    }

    public void StopScan()
    {
        locationMgr.StopMonitoring(region);
        locationMgr.StopRangingBeacons(region);
        IsScanning = false;

        mtManager.StopScan();
    }

    public void FillBeacon(Beacon beacon, object ibeacon)
    {
        //CLBeacon ib = (CLBeacon)ibeacon;
        MTPeripheral periph = (MTPeripheral)ibeacon;

        MTFrameHandler framer = periph.Framer;
        string name = framer.Name;          // name of device, may nil
        nint rssi = framer.Rssi;          // rssi
        nint battery = framer.Battery;    // battery,may nil
        string mac = framer.Mac;            // mac address,may nil
        MinewFrame[] frames = framer.AdvFrames;    // all data frames of device(such as:iBeacon,UID,URL...)

        foreach(MinewFrame frame in frames)
        {
            switch(frame.FrameType)
            {
                case FrameType.iBeacon:
                    MinewiBeacon mb = (MinewiBeacon)frame;
                    beacon.Major = (int)mb.Major;
                    beacon.Minor = (int)mb.Minor;

                    break;
                case FrameType.Uid:
                    MinewUID uid = (MinewUID)frame;
                    beacon.ProximityUuid = uid.NamespaceId;

                    break;
                case FrameType.DeviceInfo:
                    MinewDeviceInfo di = (MinewDeviceInfo)frame;

                    break;
                case FrameType.Connectable:
                    int i = 0;

                    break;
                case FrameType.Tlm:
                    int tlm = 0;
                    break;
                case FrameType.AccSensor:
                    int acc = 0;
                    break;
                case FrameType.LightSensor:
                    int ls = 0;
                    break;
                case FrameType.Unknown:
                    int j = 0;

                    break;
            }
        }

        //beacon.Major = (int)ib.Major;
        //beacon.Minor = (int)ib.Minor;
        //beacon.ProximityUuid = ib.ProximityUuid.ToString();

        //if (ib.Accuracy != -1)
        //{
        //  beacon.Accuracy = ib.Accuracy;

        //  beacon.Proximity = (int)ib.Proximity;

        //  beacon.Rssi = (int)ib.Rssi;

        //  beacon.LastUpdate = DateTime.Now;
        //}
        //else
        //{

        //}

        var existing = beaconPeriphList.FirstOrDefault(bp => bp.Key == beacon);
        var def = default(KeyValuePair<Beacon, MTPeripheral>);
        if (existing.Equals(def))
            beaconPeriphList.Add(new KeyValuePair<Beacon, MTPeripheral>(beacon, periph));
    }

    public void Dispose()
    {           
        locationMgr.DidRangeBeacons -= LocationMgr_DidRangeBeacons;
        locationMgr.RangingBeaconsDidFailForRegion -= LocationMgr_RangingBeaconsDidFailForRegion;
        locationMgr.Dispose();
        region.Dispose();
    }

    public void Connect(Beacon beacon)
    {
        MTPeripheral periph = beaconPeriphList.First(bp => bp.Key == beacon).Value;
        periph.Connector.StatusChangedHandler += (conStatus, error)=> {

            var di = periph.Connector.InfoDict;
            var mac = periph.Connector.MacString;
            var connectable = periph.Connector.Connectable;
            var version = periph.Connector.Version;
            var passStat = periph.Connector.PasswordStatus;

            var conFeature = periph.Connector.Feature;
            var slotAttitude = conFeature.SlotAtitude;
            var featureSupport = conFeature.FeatureSupported;
            var supFrames = conFeature.SupportedFrames;
            var supTxpower = conFeature.SupportedTxpowers;

            if (conStatus == ConnectionStatus.Disconnected)
                mtManager.StartScan((periperials) => {
                    BeaconRanged?.Invoke(this, new BeaconsRangededArgs(periperials, Device.RuntimePlatform));
                });
        };

        mtManager.ConnectToPeriperal(periph, (passBlock)=> {
            passBlock("minew123");
        });

    }

}

}

wescur88 commented 6 years ago

// // 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 ObjCRuntime {

[CompilerGenerated]
static partial class Trampolines {

    [DllImport ("/usr/lib/libobjc.dylib")]
    static extern IntPtr _Block_copy (IntPtr ptr);

    [DllImport ("/usr/lib/libobjc.dylib")]
    static extern void _Block_release (IntPtr ptr);

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.MTCOperationBlock))]
    internal delegate void DMTCOperationBlock (IntPtr block, bool arg0, IntPtr arg1);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDMTCOperationBlock {
        static internal readonly DMTCOperationBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DMTCOperationBlock))]
        static unsafe void Invoke (IntPtr block, bool arg0, IntPtr arg1) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.MTCOperationBlock) (descriptor->Target);
            if (del != null)
                del (arg0,  Runtime.GetNSObject<NSError> (arg1));
        }
    } /* class SDMTCOperationBlock */

    internal class NIDMTCOperationBlock {
        IntPtr blockPtr;
        DMTCOperationBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDMTCOperationBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DMTCOperationBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDMTCOperationBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.MTCOperationBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTCOperationBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDMTCOperationBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (bool arg0, NSError arg1)
        {
            invoker (blockPtr, arg0, arg1 == null ? IntPtr.Zero : arg1.Handle);
        }
    } /* class NIDMTCOperationBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.MTHTHistoryBlock))]
    internal delegate void DMTHTHistoryBlock (IntPtr block, IntPtr arg0, nuint arg1);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDMTHTHistoryBlock {
        static internal readonly DMTHTHistoryBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DMTHTHistoryBlock))]
        static unsafe void Invoke (IntPtr block, IntPtr arg0, nuint arg1) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.MTHTHistoryBlock) (descriptor->Target);
            if (del != null)
                del ( Runtime.GetNSObject<MTBeaconPlusBinding.MTSensorData> (arg0), (global::MTBeaconPlusBinding.EndStatus) (ulong) arg1);
        }
    } /* class SDMTHTHistoryBlock */

    internal class NIDMTHTHistoryBlock {
        IntPtr blockPtr;
        DMTHTHistoryBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDMTHTHistoryBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DMTHTHistoryBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDMTHTHistoryBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.MTHTHistoryBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTHTHistoryBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDMTHTHistoryBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (global::MTBeaconPlusBinding.MTSensorData arg0, global::MTBeaconPlusBinding.EndStatus arg1)
        {
            invoker (blockPtr, arg0 == null ? IntPtr.Zero : arg0.Handle, (nuint) (UInt64) arg1);
        }
    } /* class NIDMTHTHistoryBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.MTPasswordRequireBlock))]
    internal delegate void DMTPasswordRequireBlock (IntPtr block, IntPtr arg0);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDMTPasswordRequireBlock {
        static internal readonly DMTPasswordRequireBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DMTPasswordRequireBlock))]
        static unsafe void Invoke (IntPtr block, IntPtr arg0) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.MTPasswordRequireBlock) (descriptor->Target);
            if (del != null)
                del ((MTBeaconPlusBinding.MTPasswordBlock) Marshal.GetDelegateForFunctionPointer (arg0, typeof (MTBeaconPlusBinding.MTPasswordBlock)));
        }
    } /* class SDMTPasswordRequireBlock */

    internal class NIDMTPasswordRequireBlock {
        IntPtr blockPtr;
        DMTPasswordRequireBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDMTPasswordRequireBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DMTPasswordRequireBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDMTPasswordRequireBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.MTPasswordRequireBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTPasswordRequireBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDMTPasswordRequireBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke ([BlockProxy (typeof (ObjCRuntime.Trampolines.NIDMTPasswordBlock))]global::MTBeaconPlusBinding.MTPasswordBlock arg0)
        {
            BlockLiteral *block_ptr_arg0;
            BlockLiteral block_arg0;
            block_arg0 = new BlockLiteral ();
            block_ptr_arg0 = &block_arg0;
            block_arg0.SetupBlockUnsafe (Trampolines.SDMTPasswordBlock.Handler, arg0);

            invoker (blockPtr, (IntPtr) block_ptr_arg0);
            block_ptr_arg0->CleanupBlock ();

        }
    } /* class NIDMTPasswordRequireBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.MTScanBlock))]
    internal delegate void DMTScanBlock (IntPtr block, IntPtr arg0);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDMTScanBlock {
        static internal readonly DMTScanBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DMTScanBlock))]
        static unsafe void Invoke (IntPtr block, IntPtr arg0) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.MTScanBlock) (descriptor->Target);
            if (del != null)
                del (NSArray.ArrayFromHandle<global::MTBeaconPlusBinding.MTPeripheral> (arg0));
        }
    } /* class SDMTScanBlock */

    internal class NIDMTScanBlock {
        IntPtr blockPtr;
        DMTScanBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDMTScanBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DMTScanBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDMTScanBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.MTScanBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTScanBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDMTScanBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (global::MTBeaconPlusBinding.MTPeripheral[] arg0)
        {
            var nsa_arg0 = arg0 == null ? null : NSArray.FromNSObjects (arg0);

            invoker (blockPtr, nsa_arg0 == null ? IntPtr.Zero : nsa_arg0.Handle);
            if (nsa_arg0 != null)
                nsa_arg0.Dispose ();

        }
    } /* class NIDMTScanBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.MTStatusChangeBlock))]
    internal delegate void DMTStatusChangeBlock (IntPtr block, nint arg0, IntPtr arg1);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDMTStatusChangeBlock {
        static internal readonly DMTStatusChangeBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DMTStatusChangeBlock))]
        static unsafe void Invoke (IntPtr block, nint arg0, IntPtr arg1) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.MTStatusChangeBlock) (descriptor->Target);
            if (del != null)
                del ((global::MTBeaconPlusBinding.ConnectionStatus) (long) arg0,  Runtime.GetNSObject<NSError> (arg1));
        }
    } /* class SDMTStatusChangeBlock */

    internal class NIDMTStatusChangeBlock {
        IntPtr blockPtr;
        DMTStatusChangeBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDMTStatusChangeBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DMTStatusChangeBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDMTStatusChangeBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.MTStatusChangeBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTStatusChangeBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDMTStatusChangeBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (global::MTBeaconPlusBinding.ConnectionStatus arg0, NSError arg1)
        {
            invoker (blockPtr, (nint) (Int64) arg0, arg1 == null ? IntPtr.Zero : arg1.Handle);
        }
    } /* class NIDMTStatusChangeBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.MTTriggerWroteBlock))]
    internal delegate void DMTTriggerWroteBlock (IntPtr block, bool arg0);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDMTTriggerWroteBlock {
        static internal readonly DMTTriggerWroteBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DMTTriggerWroteBlock))]
        static unsafe void Invoke (IntPtr block, bool arg0) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.MTTriggerWroteBlock) (descriptor->Target);
            if (del != null)
                del (arg0);
        }
    } /* class SDMTTriggerWroteBlock */

    internal class NIDMTTriggerWroteBlock {
        IntPtr blockPtr;
        DMTTriggerWroteBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDMTTriggerWroteBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DMTTriggerWroteBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDMTTriggerWroteBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.MTTriggerWroteBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTTriggerWroteBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDMTTriggerWroteBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (bool arg0)
        {
            invoker (blockPtr, arg0);
        }
    } /* class NIDMTTriggerWroteBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.OTAErrorBlock))]
    internal delegate void DOTAErrorBlock (IntPtr block, IntPtr arg0);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDOTAErrorBlock {
        static internal readonly DOTAErrorBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DOTAErrorBlock))]
        static unsafe void Invoke (IntPtr block, IntPtr arg0) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.OTAErrorBlock) (descriptor->Target);
            if (del != null)
                del ( Runtime.GetNSObject<NSError> (arg0));
        }
    } /* class SDOTAErrorBlock */

    internal class NIDOTAErrorBlock {
        IntPtr blockPtr;
        DOTAErrorBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDOTAErrorBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DOTAErrorBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDOTAErrorBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.OTAErrorBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.OTAErrorBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDOTAErrorBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (NSError arg0)
        {
            invoker (blockPtr, arg0 == null ? IntPtr.Zero : arg0.Handle);
        }
    } /* class NIDOTAErrorBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.OTAProgressBlock))]
    internal delegate void DOTAProgressBlock (IntPtr block, float arg0);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDOTAProgressBlock {
        static internal readonly DOTAProgressBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DOTAProgressBlock))]
        static unsafe void Invoke (IntPtr block, float arg0) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.OTAProgressBlock) (descriptor->Target);
            if (del != null)
                del (arg0);
        }
    } /* class SDOTAProgressBlock */

    internal class NIDOTAProgressBlock {
        IntPtr blockPtr;
        DOTAProgressBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDOTAProgressBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DOTAProgressBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDOTAProgressBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.OTAProgressBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.OTAProgressBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDOTAProgressBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (float arg0)
        {
            invoker (blockPtr, arg0);
        }
    } /* class NIDOTAProgressBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.OTAStateBlock))]
    internal delegate void DOTAStateBlock (IntPtr block, nint arg0);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDOTAStateBlock {
        static internal readonly DOTAStateBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DOTAStateBlock))]
        static unsafe void Invoke (IntPtr block, nint arg0) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.OTAStateBlock) (descriptor->Target);
            if (del != null)
                del ((global::MTBeaconPlusBinding.OTAState) (long) arg0);
        }
    } /* class SDOTAStateBlock */

    internal class NIDOTAStateBlock {
        IntPtr blockPtr;
        DOTAStateBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDOTAStateBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DOTAStateBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDOTAStateBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.OTAStateBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.OTAStateBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDOTAStateBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (global::MTBeaconPlusBinding.OTAState arg0)
        {
            invoker (blockPtr, (nint) (Int64) arg0);
        }
    } /* class NIDOTAStateBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.PowerStateBlock))]
    internal delegate void DPowerStateBlock (IntPtr block, nuint arg0);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDPowerStateBlock {
        static internal readonly DPowerStateBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DPowerStateBlock))]
        static unsafe void Invoke (IntPtr block, nuint arg0) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.PowerStateBlock) (descriptor->Target);
            if (del != null)
                del ((global::MTBeaconPlusBinding.PowerState) (ulong) arg0);
        }
    } /* class SDPowerStateBlock */

    internal class NIDPowerStateBlock {
        IntPtr blockPtr;
        DPowerStateBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDPowerStateBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DPowerStateBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDPowerStateBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.PowerStateBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.PowerStateBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDPowerStateBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (global::MTBeaconPlusBinding.PowerState arg0)
        {
            invoker (blockPtr, (nuint) (UInt64) arg0);
        }
    } /* class NIDPowerStateBlock */

    [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
    [UserDelegateType (typeof (global::MTBeaconPlusBinding.MTPasswordBlock))]
    internal delegate void DMTPasswordBlock (IntPtr block, IntPtr arg0);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDMTPasswordBlock {
        static internal readonly DMTPasswordBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DMTPasswordBlock))]
        static unsafe void Invoke (IntPtr block, IntPtr arg0) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.MTPasswordBlock) (descriptor->Target);
            if (del != null)
                del (NSString.FromHandle (arg0));
        }
    } /* class SDMTPasswordBlock */

    internal class NIDMTPasswordBlock {
        IntPtr blockPtr;
        DMTPasswordBlock invoker;

        [Preserve (Conditional=true)]
        public unsafe NIDMTPasswordBlock (BlockLiteral *block)
        {
            blockPtr = _Block_copy ((IntPtr) block);
            invoker = block->GetDelegateForBlock<DMTPasswordBlock> ();
        }

        [Preserve (Conditional=true)]
        ~NIDMTPasswordBlock ()
        {
            _Block_release (blockPtr);
        }

        [Preserve (Conditional=true)]
        public unsafe static global::MTBeaconPlusBinding.MTPasswordBlock Create (IntPtr block)
        {
            if (block == IntPtr.Zero)
                return null;
            if (BlockLiteral.IsManagedBlock (block)) {
                var existing_delegate = ((BlockLiteral *) block)->Target as global::MTBeaconPlusBinding.MTPasswordBlock;
                if (existing_delegate != null)
                    return existing_delegate;
            }
            return new NIDMTPasswordBlock ((BlockLiteral *) block).Invoke;
        }

        [Preserve (Conditional=true)]
        unsafe void Invoke (string arg0)
        {
            var nsarg0 = NSString.CreateNative (arg0);

            invoker (blockPtr, nsarg0);
            NSString.ReleaseNative (nsarg0);

        }
    } /* class NIDMTPasswordBlock */
}

}

wescur88 commented 6 years ago

This is the problem block of code. It is generated by the compiler


[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)] [UserDelegateType (typeof (global::MTBeaconPlusBinding.MTPasswordRequireBlock))] internal delegate void DMTPasswordRequireBlock (IntPtr block, IntPtr arg0);

    //
    // This class bridges native block invocations that call into C#
    //
    static internal class SDMTPasswordRequireBlock {
        static internal readonly DMTPasswordRequireBlock Handler = Invoke;

        [MonoPInvokeCallback (typeof (DMTPasswordRequireBlock))]
        static unsafe void Invoke (IntPtr block, IntPtr arg0) {
            var descriptor = (BlockLiteral *) block;
            var del = (global::MTBeaconPlusBinding.MTPasswordRequireBlock) (descriptor->Target);
            if (del != null)
                del ((MTBeaconPlusBinding.MTPasswordBlock) Marshal.GetDelegateForFunctionPointer (arg0, typeof (MTBeaconPlusBinding.MTPasswordBlock)));
        }
    } /* class SDMTPasswordRequireBlock */

wescur88 commented 6 years ago

Issue resolved. In the MTBeaconPlusBinding project I had to add the [BlockCallback] for this delegate: delegate void MTPasswordRequireBlock(MTPasswordBlock arg0); //old delegate void MTPasswordRequireBlock([BlockCallback] MTPasswordBlock arg0); //new