Popular Posts

Saturday, December 7, 2013

Autofac issue not resolving dependency

Had a nightmare where Autofac was unable to resolve the controller though my unit tests were all ok. The only thing was when running the MVC application the dependency was not resolved.

        [TestMethod()]
        public void Initialise_CategoryController_Ioc()
        {
            
            IContainer container = AutofacBootstrap.GetContainer();
            CategoryController controller = new CategoryController(container.Resolve<ICategoryBusinessObject>());
 
        }
 
        [TestMethod()]
        public void Initialise_ProductController_Ioc()
        {
 
            IContainer container = AutofacBootstrap.GetContainer();
            ProductController controller = new ProductController(container.Resolve<IProductBusinessObject>());
 
        }
 
        [TestMethod()]
        public void Initialise_SubCategoryController_Ioc()
        {
 
            IContainer container = AutofacBootstrap.GetContainer();
            SubCategoryController controller = new SubCategoryController(container.Resolve<ISubCategoryBusinessObject>());
 
        }

All the above tests were ok and resolving the dependency. Couldn't see what was going wrong. After hours of investigation finally found that there were some warnings that:

The primary reference "Mydll.dll" 
could not be resolved because it has an indirect dependency on the assembly "EntityFramework, Version=6.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0". 
KidsWear.DependencyResolver

The solution was:

- Uninstall the entity framework package using Nuget 
- Re-add the package reference using the nuget

The reference was in the composite root (DependencyResolver) project!!



No comments:

Post a Comment