0

I faced a question with PaymillWrapper for Xamarin.Android with MVVMCross.

I installed the latest version 3.3.0.

And added it to my App.cs:

using MvvmCross.Platform;
using MvvmCross.Platform.IoC;
using PaymillWrapper;

namespace App.Core
{
    public class App : MvvmCross.Core.ViewModels.MvxApplication
    {
        public override void Initialize()
        {
            CreatableTypes()
                .EndingWith("Service")
                .AsInterfaces()
                .RegisterAsLazySingleton();

            RegisterNavigationServiceAppStart<ViewModels.AppViewModel>();

            PaymillContext paymillContext = new PaymillContext("my-private-token");
        }
    }
}

After that, I try to call it from my ViewModel:

using MvvmCross.Core.ViewModels;
using MvvmCross.Platform;
using PaymillWrapper;
using PaymillWrapper.Models;
using PaymillWrapper.Service;
using System;
using System.Windows.Input;

namespace App.Core.ViewModels
{
    public class AppViewModel : MvxViewModel
    {
     ...

    PaymentService paymentService = paymillContext.PaymentService;

    public ICommand PayCommand => new MvxCommand(() => {

        Payment payment = paymentService.CreateWithTokenAsync("my-public-token").Result;
    });

But I can see the following error: enter image description here

I tried to move initialization to ViewModel:

static PaymillContext paymillContext = new PaymillContext("my-private-token");

PaymentService paymentService = paymillContext.PaymentService;

public ICommand PayCommand => new MvxCommand(() => {

    Payment payment = paymentService.CreateWithTokenAsync("my-public-token").Result;
    });

In this case, I don't have underlines but the project doesn't build successfully:

Error       Exception while loading assemblies: System.IO.FileNotFoundException: 
Could not load assembly 'PaymillWrapper, Version=0.3.3.0, Culture=neutral, PublicKeyToken='. 
Perhaps it doesn't exist in the Mono for Android profile?
File name: 'PaymillWrapper.dll'
   at 
Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve
(AssemblyNameReference reference, ReaderParameters parameters)
   at 
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences
(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, 
AssemblyDefinition assembly, Boolean topLevel)
   at 
Xamarin.Android.Tasks.ResolveAssemblies.Execute
(DirectoryAssemblyResolver resolver)    App.Droid           

What am I missing here?

I tried this solution with different versions of MVVMCross (5.2.1, 5.6.0, 5.7.0).

NaSt
  • 301
  • 1
  • 5
  • 16
  • Clean the solution and delete bin and obj folder --> Delete all contents of the Packages folder (all the DLL's referenced through Nuget) --> Restart the solution --> ReBuild (this will cause Nuget to get all DLL's again based on the packages.config) – York Shen Jun 05 '18 at 11:39
  • @YorkShen, I tried but it didn't help me – NaSt Jun 05 '18 at 13:54
  • Why do you think you can access `paymillContext` defined in `App.cs` in a totally different scope? Also `PaymillWrapper` NuGet package is .NET 4.5. Not compatible with Xamarin targets, you cannot load that. – Cheesebaron Jun 05 '18 at 17:35
  • @Cheesebaron, my colleagues successfully did it. So it's real. – NaSt Jun 05 '18 at 17:47
  • It won't work at runtime. And the scoping thing I don't believe it. Unless it is a static field or property in the App class and you actually write `App.paymillContext` – Cheesebaron Jun 06 '18 at 09:29

0 Answers0