2
votes

When using the mvvmCross File Plugin I am getting the below error. I tried using the N-14 code sample which uses "File Plugin 3.1.1-beta" and I get the error and I also use a fresh new project, downloading the lastest plugin version from nuGet and I also get the same error.

This seems to be the same problem as this guy had:

https://github.com/MvvmCross/MvvmCross/issues/510

This seems to be the main line in the error message:

Failed to resolve parameter for parameter fileStore of type IMvxFileStor
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00000] in <filename unknown>:0 

I have tried re-starting xamarin studio and my MacPro etc. I have used the location and messenger plugins without any issues

Please advise

Trace:

2014-03-17 20:37:44.836 MCOTaxiIOS[2730:60b] TouchNavigation:Diagnostic: 0.56 Navigate requested [0:] TouchNavigation:Diagnostic: 0.56 Navigate requested Resolved pending breakpoint at '/Developer/Projects/MCO/MCO.IOS/Views/FirstView.cs:58,1' to MonoTouch.UIKit.UIViewController MCO.IOS.Views.FirstView.CreateTabFor (string title, string imageName, Cirrious.MvvmCross.ViewModels.IMvxViewModel viewModel) [0x0002f]. [0:] 2014-03-17 20:37:44.875 MCOIOS[2730:60b] mvx:Diagnostic: 0.59 Request is null - assuming this is a TabBar type situation where ViewDidLoad is called during construction... patching the request now - but watch out for problems with virtual calls during construction [0:] mvx:Diagnostic: 0.59 Request is null - assuming this is a TabBar type situation where ViewDidLoad is called during construction... patching the request now - but watch out for problems with virtual calls during construction Resolved pending breakpoint at '/Developer/Projects/MCO/MCO.Common/Services/LocationService.cs:110,1' to void MCO.Common.LocationService.OnError (Cirrious.MvvmCross.Plugins.Location.MvxLocationError error) [0x00001]. [0:] 2014-03-17 20:37:44.917 MCOIOS[2730:60b] mvx:Warning: 0.64 Problem creating viewModel of type FirstViewModel - problem MvxIoCResolveException: Failed to resolve parameter for parameter fileStore of type IMvxFileStore when creating MCO.Common.ViewModels.FirstViewModel at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00000] in :0 at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in :0 at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00000] in :0 at Cirrious.MvvmCross.ViewModels.MvxDefaultViewModelLocator.TryLoad (System.Type viewModelType, IMvxBundle parameterValues, IMvxBundle savedState, IMvxViewModel& viewModel) [0x00000] in :0 [0:] mvx:Warning: 0.64 Problem creating viewModel of type FirstViewModel - problem MvxIoCResolveException: Failed to resolve parameter for parameter fileStore of type IMvxFileStore when creating MCO.Common.ViewModels.FirstViewModel at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00000] in :0 at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in :0 at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00000] in :0 at Cirrious.MvvmCross.ViewModels.MvxDefaultViewModelLocator.TryLoad (System.Type viewModelType, IMvxBundle parameterValues, IMvxBundle savedState, IMvxViewModel& viewModel) [0x00000] in :0

Stack trace:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Failed to construct and initialize ViewModel for type CollectABull.Core.ViewModels.FirstViewModel from locator MvxDefaultViewModelLocator - check MvxTrace for more information at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState, IMvxViewModelLocator viewModelLocator) [0x00000] in :0 at Cirrious.MvvmCross.ViewModels.MvxViewModelLoader.LoadViewModel (Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request, IMvxBundle savedState) [0x00000] in :0 at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel (IMvxTouchView touchView) [0x00000] in :0 at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods+<>c_DisplayClass1.b_0 () [0x00000] in :0 at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (IMvxView view, System.Func`1 viewModelLoader) [0x00000] in :0 at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate (IMvxTouchView touchView) [0x00000] in :0 at Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled (System.Object sender, System.EventArgs e) [0x00000] in :0 at at (wrapper delegate-invoke) :invoke_void_this__object_EventArgs (object,System.EventArgs) at Cirrious.CrossCore.Core.MvxDelegateExtensionMethods.Raise (System.EventHandler eventHandler, System.Object sender) [0x00000] in :0 at Cirrious.CrossCore.Touch.Views.MvxEventSourceTabBarController.ViewDidLoad () [0x00000] in :0 at MCO.IOS.Views.FirstView.ViewDidLoad () [0x00002] in /Developer/Projects/MCO/MCO.IOS/Views/FirstView.cs:26 at MCO.IOS.Views.FirstView..ctor () [0x0000f] in /Developer/Projects/MCO/MCO.IOS/Views/FirstView.cs:18 at at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:537

1
Did you install the plugin in both your Core PCL project as well as your iOS project? Make sure there is a Bootstrap class for the File plugin. This is how Mvx auto-registers plugins.Kiliman
That was it, i didn't add the plugin to the IOS project! Can you answer the question so I can accept it?Bob

1 Answers

9
votes

MvvmCross plugins typically come in 2 parts. There is the interface that goes in the core PCL project. Then there are the platform specific implementations: Android, iOS, etc.

If you look in the NuGet package, you will see various platform targets. NuGet will reference the correct assembly based on your project type.

MvvmCross uses IoC to inject dependencies at run-time. Your ViewModel will take a reference to IFileStore and MvvmCross will try to resolve that dependency when constructing the ViewModel.

However, MvvmCross can only resolve it if a specific implementation of the interface has been registered. Normally you would have code in App.Initialize to register all types ending with "Service". You can also explicitly register types.

Since plugins have a common pattern, MvvmCross has support to automatically register plugins at startup. The way it does this is via a Bootstrap file that is added to the platform specific project by NuGet. This typically looks like:

public class FilePluginBootstrap
    : MvxPluginBootstrapAction<Cirrious.MvvmCross.Plugins.File.PluginLoader>
{
}

At startup, MvvmCross looks for all types that implement IMvxBootstrapAction. Each plugin also has a PluginLoader class that registers the type in MvvmCross. Something like this:

public class Plugin
    : IMvxPlugin          
{
    public void Load()
    {
        Mvx.RegisterType<IMvxFileStore, MvxTouchFileStore>();
    }
}

So as you can see, by installing the plugin package in both the Core PCL project as well as your platform specific project, MvvmCross has all the parts in place to automatically register the implementation in the IoC container.

TL;DR: Make sure you install your plugins in both Core PCL and platform specific projects.