1
votes

I've been using MvvmCross v1 for a while now, & I find it really useful & not too hard to use! So I bit the bullet & decided to use vnext for our next project. All was well until I tried to use a plugin, and it crashes with the following output -

2013-03-21 18:14:27.121 MyApp[85942:11903] mvx: Diagnostic:   0,00 Setup: Text serialization start
2013-03-21 18:14:27.124 MyApp[85942:11903] mvx: Diagnostic:   0,03 Setup: PlatformServices start
2013-03-21 18:14:27.125 MyApp[85942:11903] mvx: Diagnostic:   0,03 Setup: ViewModelFramework start
2013-03-21 18:14:27.126 MyApp[85942:11903] mvx: Diagnostic:   0,03 Setup: PluginManagerFramework start
2013-03-21 18:14:27.127 MyApp[85942:11903] mvx: Diagnostic:   0,03 Setup: App start

Unhandled Exception:
0   MyApp                      0x00079b12 mono_handle_exception_internal_first_pass + 3058
1   MyApp                      0x0007b1e2 mono_handle_exception_internal + 1602
2   MyApp                      0x0007bd2f mono_handle_exception + 47
3   MyApp                      0x000bce22 mono_x86_throw_exception + 306
4   ???                                 0x07986f8f 0x0 + 127430543
at Cirrious.MvvmCross.Plugins.MvxBasePluginManager.ExceptionWrappedLoadPlugin (System.Type) <IL 0x00002, 0x0001f>
at Cirrious.MvvmCross.Plugins.MvxBasePluginManager.EnsureLoaded<T> () <IL 0x00030, 0x0008c>
at Cirrious.MvvmCross.Plugins.Share.PluginLoader.EnsureLoaded () <IL 0x00008, 0x00029>
at MyApp.Core.BaseApp.InitialisePlugins () [0x00000] in /Users/franklyn/Documents/Programming/MyApp/MyApp.Core/App.cs:42

It happens whenever I try lo load a plugin which has a "Touch" project element, others such as the JsonLocalisation plugin which don't have, load fine.

If anyone else has come across this & knows the fix, I'd be very pleased to hear from them.

1
Have you tried stepping into it while in debug mode and narrow it down as to where exactly it breaks?Cheesebaron

1 Answers

2
votes

For Android, plugins are loaded just because they are there - they are files and can be loaded through Assembly.Load

For iOS, plugins cannot be loaded this way because of the Ahead-Of-Time compilation requirement.

To solve this, all platform specific plugins in iOS have to be registered during setup.

You can see this code in AddPluginLoaders in Setup in all the samples - see https://github.com/slodge/MvvmCross/blob/vnext/Sample%20-%20TwitterSearch/TwitterSearch.UI.Touch/Setup.cs

protected override void AddPluginsLoaders(MvxLoaderPluginRegistry registry)
{
    registry.AddConventionalPlugin<Cirrious.MvvmCross.Plugins.Visibility.Touch.Plugin>();
    registry.AddConventionalPlugin<Cirrious.MvvmCross.Plugins.File.Touch.Plugin>();
    registry.AddConventionalPlugin<Cirrious.MvvmCross.Plugins.DownloadCache.Touch.Plugin>();
    base.AddPluginsLoaders(registry);
}

Overall, the plugin mechanism is much better than the old v1 code because it means less unwanted code is included in your app and because it is extensible.


For a recent discussion on why Assembly.Load cannot be used in iOS, see http://forums.xamarin.com/discussion/comment/7882 - I have tried to avoid this step.