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

Came across a crash the oth­er day whilst try­ing to imple­ment a cus­tom View­CellRen­der­er for a Xamar­in iOS app I’m work­ing 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 cre­ated a sub­class of ListView and changed the Cach­ing Strategy from RetainElement to RecycleElement. Some­thing like this:

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

Then I star­ted my app, had a scroll of my MyListView and boom it crashed. I then tried imple­ment­ing IBoxedCell like the error mes­sage said, but no dice:

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

The Solu­tion #

After some search­ing, the answer was found in a bug tick­et on Xamarin’s Bug­zilla. Des­pite what the error sug­gests, your nat­ive view cell needs to imple­ment Xamarin’s INativeElementView, not IBoxedCell.

If you’re work­ing with iOS, it’ll end up look­ing some­thing like this:

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