Xamarin crashing with "System.InvalidOperationException: Implement IBoxedCell on cell renderer"

Came across a crash the other day whilst trying to implement a custom ViewCellRenderer for a Xamarin iOS app I’m working on:

System.InvalidOperationException: Implement IBoxedCell on cell renderer:
MyApp.iOS.Controls.MyNativeViewCell, MyAppiOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
at Xamarin.Forms.Platform.iOS.ContextActionsCell.Xamarin.Forms.INativeElementView.get_Element () [0x00028] in <filename unknown>:0 

I created a subclass of ListView and changed the Caching Strategy from RetainElement to RecycleElement. Something like this:

public class MyListView : ListView
{
  public MyListView () : base (ListViewCachingStrategy.RecycleElement)
  {
    ...
  }
}

Then I started my app, had a scroll of my MyListView and boom it crashed. I then tried implementing IBoxedCell like the error message said, but no dice:

Error CS0246: The type or namespace name `IBoxedCell' could not be found. Are you missing an assembly reference? (CS0246)

The Solution #

After some searching, the answer was found in a bug ticket on Xamarin’s Bugzilla. Despite what the error suggests, your native view cell needs to implement Xamarin’s INativeElementView, not IBoxedCell.

If you’re working with iOS, it’ll end up looking something like this:

public class MyNativeViewCell : UITableViewCell, INativeElementView
{
  public Element Element { get; set; }
}