Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

DependencyService: System.MissingMethodException: Default constructor not found for [Interface]

$
0
0

I am receiving this error when using the Dependency Service on a Xamarin.Forms PCL. I have seen answers to this error that involve iOS and the Linker.
However, I am running this on Android and the Linker is off. Debug mode as well.

The constructor it is telling me it cannot find the default constructor for the Interface in the PCL.

I thought it may have been an issue with some renaming I did (I used refactor tool and made sure all necessary changes were being made) so I deleted those folders/files and remade them. Still nothing :(

Here is my related code.

Interface:
`namespace Enchantum.Functions
{
public interface PaymentProcessor
{

    void setUpCard(String cardNumber,
        int expirationMonth,
        int expirationYear,
        String CVC);

    Task cardTokenizer();

    void backendCardCharge();

}`

Android:
`[assembly: Xamarin.Forms.Dependency(typeof(PaymentProcessor_Android))]

namespace Enchantum.Droid.Functions_Android
{
class PaymentProcessor_Android : PaymentProcessor
{
public PaymentProcessor_Android() { }

    private Card mCard;
    private Token mToken;

    public void setUpCard(String cardNumber, int expirationMonth,
        int expirationYear, String cvcCode)
    {
        Card card = new Card
        {
            Number = cardNumber,
            ExpiryMonth = expirationMonth,
            ExpiryYear = expirationYear,
            CVC = cvcCode
        };

        mCard = card;
    }

    public async Task cardTokenizer()
    {
        mToken = await StripeClient.CreateToken(mCard);
    }

    /*TODO: 
     * */

    public void backendCardCharge()
    {
        throw new NotImplementedException();
    }

`

iOS:
`[assembly: Xamarin.Forms.Dependency(typeof(PaymentProcessor_iOS))]

namespace Enchantum.iOS.Functions_iOS
{
class PaymentProcessor_iOS : PaymentProcessor
{
public PaymentProcessor_iOS() { }

    private Card mCard;
    private Token mToken;

    public void setUpCard(String cardNumber, int expirationMonth,
        int expirationYear, String cvcCode)
    {
        Card card = new Card
        {
            Number = cardNumber,
            ExpiryMonth = expirationMonth,
            ExpiryYear = expirationYear,
            CVC = cvcCode
        };

        mCard = card;

    }

    public async Task cardTokenizer()
    {
        mToken = await StripeClient.CreateToken(mCard);
    }

    /*TODO: 
    public void backendCardCharge()
    {
        throw new NotImplementedException();
    }




}`

Implementation in a Xamarin.Form Content Page:
DependencyService.Get<PaymentProcessor>().setUpCard( cardNumber, expirationMonth, expirationYear, CVC);

My error, again : "System.MissingMethodException: Default constructor not found for type Enchantum.Functions.PaymentProcessor"

P.S. Pardon my incorrect naming convention for the Interface.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>