views:

767

answers:

2

In a Composite Application (Prism), when my module loads, I get this error:

{"The current build operation (build key Build Key[CustomersModul.ViewModels.CustomerAllViewModel, null]) failed: The parameter view could not be resolved when attempting to call constructor CustomersModul.ViewModels.CustomerAllViewModel(CustomersModul.Views.CustomerAllView view). (Strategy type Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy, index 2)"}

I am resolving this class:

CustomerAllViewModel layoutManager = this.container.Resolve<CustomerAllViewModel>();

And that class looks like this:

public class CustomerAllViewModel : ViewModelBase
{
    public CustomerAllView View { get; set; }
    public ICommand TextChangeCommand { get; set; }
    private Customer customer;

public CustomerAllViewModel(CustomerAllView view)
{
    View = view;
    view.DataContext = this;
    ...

Normally I resolve Presenters which have no constructor parameters and instantiate their views internally. This is the first time I am using a ViewModel which accepts a View as parameter.

Interestingly, when I go to the view with Resharper, it asks me if I want to go to the XAML or code behind, so perhaps Prism is getting confused which one to instantiate?

How can I get Prism to automatically instantiate this view (UserControl with XAML and code-behind) in the parameter?

+2  A: 

Sometimes this is actually not the error, but something else. Look at the inner exceptions, or call Microsoft.Practices.Composite.ExceptionExtensions.GetRootException(ex) to get the root exception. You'll likely find there is some error being thrown in one of your constructors you are not seeing.

Anderson Imes
A: 

Have you added the CustomerAllView to the container? I usually get this error when I have forgot to add a type to the container.

Robert Höglund