65.9K
CodeProject is changing. Read more.
Home

Solving "The IControllerFactory 'MefContrib.Web.Mvc.CompositionControllerFactory' did not return a controller for the name xxx"

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Jul 30, 2014

CPOL
viewsIcon

16835

Solving "The IControllerFactory 'MefContrib.Web.Mvc.CompositionControllerFactory' did not return a controller for the name xxx"

Solution

if you have this

        public virtual ViewResult Index(IService service)
        {
            return View();
        }

1) Make sure that the class that implements IService is decorated with the Export attribute:

[Export(typeof(IService)), PartCreationPolicy(CreationPolicy.NonShared)]
    public class ServiceImplementation : IService
    {}

2) Make sure there is no other class exporting the same contract:

[Export(typeof(IService)), PartCreationPolicy(CreationPolicy.NonShared)]
    public class AnotherServiceImplementation : IAnotherService
    {}