Oren
Oren

Reputation: 5103

MvvmCross 4.1 - MvxImageViewLoader not working

I started a new Xamarin.iOS project but I can't get the MvxImageViewLoader working. I've added the latest DownloadCache, File and Json plugins (version 4.1) and configured them inside my Setup file:

protected override void AddPluginsLoaders (MvxLoaderPluginRegistry registry)
{
    registry.AddConventionalPlugin<MvvmCross.Plugins.DownloadCache.iOS.Plugin>();
    registry.AddConventionalPlugin<MvvmCross.Plugins.File.iOS.Plugin>();

    base.AddPluginsLoaders (registry);
}

protected override void InitializeLastChance ()
{   
    MvvmCross.Plugins.DownloadCache.PluginLoader.Instance.EnsureLoaded();
    MvvmCross.Plugins.File.PluginLoader.Instance.EnsureLoaded();
    MvvmCross.Plugins.Json.PluginLoader.Instance.EnsureLoaded();

    base.InitializeLastChance ();
}

Inside a custom MvxTableViewCell I'm trying to bind an image:

public partial class MyTableViewCell : MvxTableViewCell
{
    public static readonly NSString Key = new NSString ("MyTableViewCell");
    public static readonly UINib Nib;

    private readonly MvxImageViewLoader _imageViewLoader;

    static MyTableViewCell ()
    {
        Nib = UINib.FromName ("MyTableViewCell", NSBundle.MainBundle);
    }

    public MyTableViewCell (IntPtr handle) : base (handle)
    {
        _imageViewLoader = new MvxImageViewLoader(() => imgLarge);

        this.DelayBind (() => {
            var set = this.CreateBindingSet<MyTableViewCell, MyViewModel>();                
            set.Bind (_imageViewLoader).To (vm => vm.ImageUrlLarge);
            set.Apply();
        }); 
    }
}

The relevant error in the Application Output:

mvx: Diagnostic: 366.64 failed to download image http://3.bp.blogspot.com/-2-9DK3D-bo8/T-g6U58ZU_I/AAAAAAAADpQ/NKEmG72Hl0I/s1600/Funny_Hamster_04.jpg : TypeLoadException: Could not load type 'MvxImageCache`1' from assembly ‘…/MvvmCross.Plugins.DownloadCache.dll'.
.....
at MvvmCross.Plugins.DownloadCache.MvxDynamicImageHelper`1+<RequestImageAsync>d__29[T].MoveNext () [0x001a7] in C:\vcs\git\MvvmCross-Plugins\DownloadCache\MvvmCross.Plugins.DownloadCache\MvxDynamicImageHelper.cs:135 

Looking at the error and the source code for that line, it seems the DownloadCache plugin isn't able to resolve the ImageCache:

var cache = Mvx.Resolve<IMvxImageCache<T>>();

Did I not register something that I was supposed to? Is this a bug with the latest version perhaps? All the tutorials, questions, etc I see online are for version 3.X. Has anyone gotten the DownloadCache plugin working with 4.X?

UPDATE I created a new MvvmCross solution to showcase this problem. You can reproduce the problem here: https://github.com/ogoldfinger/MvvmCrossDownloadCacheTest

Upvotes: 1

Views: 746

Answers (1)

Tri Nguyen
Tri Nguyen

Reputation: 490

Manually install this Nuget: System.Collections.Immutable

This is an issue of DownloadCache plugin, missing dependency on System.Collections.Immutable. See this: https://github.com/MvvmCross/MvvmCross-Plugins/issues/78

The issue is fixed already, so we won't need to do this in the next update of DownloadCache package.

Upvotes: 4

Related Questions