When loading my MainPage Visual Studio goes into break mode with the following error
System.MissingMethodException: Default constructor not found for type Test.Renderers.PostListViewAndroid
I updated my Custom Renderer class to support 2.5 since Context is obsolete as of version 2.5
My custom renderer is
[assembly: ExportRenderer(typeof(PostListView), typeof(PostListViewAndroid))]
namespace SocialNetwork.Droid.Renderers
{
public class PostListViewAndroid: ListViewRenderer
{
public PostListViewAndroid(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
Control.SetSelector(Android.Resource.Color.Transparent);
}
}
}
And the PostListView is simply
public class PostListView : ListView
{
}
If you are using Xamarin.Forms >= 2.5 you need to use ListViewRenderer(Context context) : base(context)
as you know
This is the source for the current ListViewRenderer
public class ListViewRenderer : ViewRenderer<ListView, AListView>, SwipeRefreshLayout.IOnRefreshListener
{
...
public ListViewRenderer(Context context) : base(context)
{
AutoPackage = false;
}
[Obsolete("This constructor is obsolete as of version 2.5. Please use ListViewRenderer(Context) instead.")]
public ListViewRenderer()
{
AutoPackage = false;
}
Notice the Obsolete
Attribute, meaning you don't need it. However it seems your problem is that your packages and references are out of alignment. Id try the following steps
Step 1
Step 2
Try updating all packages for solution in the package package console
Update-Package –reinstall
After this step, if it still hasn't worked try step 1 again
If base class does not have default empty constructor (in your case ListViewRenderer
) - you cannot do this. If it has, then add below
public PostListViewAndroid()
{
}
Its for simple reason : when derive class in instantiated, first base class constructor is invoked for initialization. So if there is no default constructor in base class, its not going to work out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With