title: Tracing an "unrecognized selector sent to instance" exception in Xamarin
body: <p>I'm trying to get this to work, but I must have made a mistake somewhere. This is the Delegate class (snipped down) as per the C headers:</p>
  
  <pre><code>@protocol PaymentEngineMiddlewareDelegate &lt;NSObject&gt;
  
  @required
  
  /*!
      @brief Delegate method for startTransaction. 
      @param transResponse - Contains all the transaction response info from the gateway
   */
  -(void)transactionComplete :(PaymentEngineTransactionResponse *)transResponse;
  @optional
  
  /*!
      @brief Delegate method for device connected. The method gets called when the device is connected
   */
  -(void)deviceConnected;
  
  /*!
    @brief Delegate method for device disconnected. The method gets called when the device is disconnected
   */
  -(void)deviceDisconnected;
  
  @end
  </code></pre>
  
  <p>For this, I have:</p>
  
  <pre><code>// @interface PaymentEngineMiddlewareDelegate : NSObject
  [BaseType(typeof(NSObject))]
  [Model]
  [Protocol]
  interface PaymentEngineMiddlewareDelegate
  {
      [Abstract]
      [Export("transactionComplete:")]
      void TransactionComplete(PaymentEngineTransactionResponse transResponse);
  
      [Export("deviceConnected")]
      void DeviceConnected();
  
      [Export("deviceDisconnected")]
      void DeviceDisconnected();
  }
  </code></pre>
  
  <p>Then for the PaymentEngineMiddleware class, the header has this:</p>
  
  <pre><code>@interface PaymentEngineMiddleware : NSObject
  
  + (PaymentEngineMiddleware *) getInstance;
  
  @property(nonatomic, strong) id&lt;PaymentEngineMiddlewareDelegate&gt; delegate;
  
  //------------------------------Device Methods------------------------------
  
  /*!
      @brief This method must be called before starting any transaction. Use it to connect to a device.
      @param deviceName The name of the device such as icmp or castle
      @param setDelegate Sets to self
  
   */
  -(void)setDevice :(NSString *)deviceName :(id)setDelegate;
  
  @end
  </code></pre>
  
  <p>And for that, I have:</p>
  
  <pre><code>// @interface PaymentEngineMiddleware : NSObject
  [BaseType(typeof(NSObject))]
  [Protocol]
  interface PaymentEngineMiddleware
  {
      // +(id)getInstance;
      [Static]
      [Export("getInstance")]
      PaymentEngineMiddleware GetInstance { get; }
  
      [Export("delegate", ArgumentSemantic.Retain)]
      PaymentEngineMiddlewareDelegate Delegate { get; set; }
  
      [Export("setDevice:setDelegate:")]
      void SetDevice(string deviceName, PaymentEngineMiddlewareDelegate setDelegate);
  }
  </code></pre>
  
  <p>In code, when I try to call the "middleware.SetDevice('name', this);" where this is a class that inherits from the delegate, I get the exception.</p>
  
  <p>Is there anything obvious that I missed or got wrong?</p>