Failed to register type using ServiceLocator in DesignTime

Jul 18, 2011 at 8:23 PM
Edited Jul 18, 2011 at 8:35 PM

Hello,

I've builded the latest 68690 changeset.
ServiceLocator is failed to register my type in the design time, so it leads to message box with text that says:

Failed to set designer view model:
Exception has been thrown by the target of an invocation.

Inner exception:
The type 'ShuttleBus.Controller.IDeparturesManager' is not registered, not even in an external container

The App.xaml.cs contains line in the ctor:

ServiceLocator.Instance.RegisterType<IDeparturesManagerDeparturesManager>();

The MainViewModel.cs contains costructors:

public MainViewModel(IDeparturesManager departuresManager) : base() 
{
	_departuresManager = departuresManager;
}
public MainViewModel()
: thisthis(Catel.IoC.ServiceLocator.Instance.ResolveType<IDeparturesManager>())
{
}

In the runtime everything is OK.

Regards,
Dima Vorotyntsev.

Jul 18, 2011 at 8:23 PM

Forgot to mention that hapens in the WP7 project.

Jul 18, 2011 at 8:26 PM
Edited Jul 18, 2011 at 8:35 PM

deleted message

Jul 18, 2011 at 8:34 PM

Hello,

I've applied workaround and pass instance of the  my DeparturesManager to ctor of the MainViewmodel from the derived DesignMainViewModel

public class DesignMainViewModel : MainViewModel
    {
        public DesignMainViewModel()
          : base(new DeparturesManager())
        {
        }
    }

 

Coordinator
Jul 19, 2011 at 5:42 AM

Great, I see you already found the issue. The application object is indeed not initialized in design time, so you'll have to create a "dummy" view model for design time data. Thanks for posting the solution here as well!