You must call EnsureLoaded on the File plugin before using the DownloadCache
Asked Answered
D

2

8

I've updated to MvvmCross version 4.2.1 from version 4.2.0 via NuGet and now the Android project crashes during startup. An MvxException is thrown during the splash screen with the message:

MvvmCross.Platform.Exceptions.MvxException: You must call EnsureLoaded on the File plugin before using the DownloadCache

I actually am calling this method in MvxAppCompatSetup.InitializeLastChance override. This worked well for me with version 4.2.0, but now the code doesn't even hit InitializeLastChance when running version 4.2.1.

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

I can't move the EnsureLoaded calls to InitializeFirstChance because there I'll get an exception because plugins haven't yet been initialized

Failed to resolve type MvvmCross.Platform.Plugins.IMvxPluginManager

The MvxSetup.InitializePluginFramework appears to be throwing this exception when InitializePluginFramework is called.

NuGet displayed error messages for each plugin I have installed during the update:

[Failure] Could not file file '...\Project.Droid\Bootstap\XXXBootstrap.cs'

The files are definitely there and the package installs without reporting an error.

What is the correct way to handle this problem?

Denishadenison answered 5/7, 2016 at 20:39 Comment(0)
T
5

Try to remove DownloadCachePluginBootstrap.cs and FilePluginBootstrap.cs just leave manual setup inside InitializeLastChance(). It seems that there is a problem with loading order.

Tow answered 6/7, 2016 at 19:16 Comment(3)
This seemed to fix the problem.Denishadenison
Ok by removing the above files from the Bootstrap folder and explicitly define the loading order in the method InitializeLastChance() it seems to solve the problem. More about the InitializeLastChance you can find at Individual customisationsDodiedodo
For those who now face MvxException: Could not find plugin loader for type MvvmCross.Plugins.File.PluginLoader there is a bit longer workaround described here github.com/MvvmCross/MvvmCross-Plugins/issues/…Reichel
U
3

As @Piotr mentioned:

Try to remove DownloadCachePluginBootstrap.cs and FilePluginBootstrap.cs just leave manual setup inside InitializeLastChance(). It seems that there is a problem with loading order.

That fixed the issue for me as well.

I just want to share my code in the Setup.cs of the iOS project because I think that's a better implementation. I didn't use InitializeLastChance(). Instead, I used AddPluginsLoaders and LoadPlugins.

    protected override void AddPluginsLoaders(MvxLoaderPluginRegistry registry)
    {
        registry.Register<MvvmCross.Plugins.File.PluginLoader, MvvmCross.Plugins.File.iOS.Plugin>();
        registry.Register<MvvmCross.Plugins.DownloadCache.PluginLoader, MvvmCross.Plugins.DownloadCache.iOS.Plugin>();
        base.AddPluginsLoaders(registry);
    }

    public override void LoadPlugins(IMvxPluginManager pluginManager)
    {
        pluginManager.EnsurePluginLoaded<MvvmCross.Plugins.File.PluginLoader>();
        pluginManager.EnsurePluginLoaded<MvvmCross.Plugins.DownloadCache.PluginLoader>();
        base.LoadPlugins(pluginManager);
    }
Unscrupulous answered 10/8, 2016 at 1:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.