SportsStore: MVC programming

I've been following Steven Sanderson's book called Pro ASP.NET MVC Framework, and I'm running into an exception:

Could not load type 'DomainModel.Abstract.IProductsRepository' from assembly 'DomainModel'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.TypeLoadException: Could not load type 'DomainModel.Abstract.IProductsRepository' from assembly 'DomainModel'

.

Line 19:         public WindsorControllerFactory()
Line 20:         {
Line 21:             container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
Line 22: 
Line 23:             var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes() where typeof(IController).IsAssignableFrom(t) select t;

Here's my WindsorControllerFactory code:

public class WindsorControllerFactory : DefaultControllerFactory
    {
        WindsorContainer container;

        public WindsorControllerFactory()
        {
            container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));

            var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes() where typeof(IController).IsAssignableFrom(t) select t;

            foreach (Type t in controllerTypes)

                container.AddComponentLifeStyle(t.FullName, t, LifestyleType.Transient);
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            return (IController)container.Resolve(controllerType);
        }
    }

My Global.asax.cs code:

protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);

            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory());
        }

And the web.config values:

<configSections>
    < section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor" />
  </configSections>

<castle>
    <components>
      <component id="ProdsRepository" service="DomainModel.Abstract.IProductsRepository, DomainModel"
                  type="DomainModel.Concrete.SqlProductsRepository, DomainModel">
        <parameters>
          < connectionString>data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|SportsStore.mdf;User Instance=true< /connectionString>
        </parameters>
      </component>
    </components>
  </castle>

My question is why could not load type 'DomainModel.Abstract.IProductsRepository' from assembly 'DomainModel'. ?

Answers


A possible explanation for this error is that the IProductsRepository interface is not public and/or is not placed inside the DomainModel.Abstract namespace in the DomainModel assembly. Make sure that the definition looks like this and that it is part of the DomainModel project:

namespace DomainModel.Abstract
{
    public interface IProductsRepository
    {
        ...
    }
}

The same stands true for the DomainModel.Concrete.SqlProductsRepository, DomainModel class that you've defined.


Need Your Help

Magento add price and color in meta description

magento meta

I would like to add product price in meta description of products. I don't write meta desc in product options, magento gets it from product desc. (it's ok to me)

Common patterns in a database

regex pattern-matching data-mining

I need to find common patterns in a database of sequences of events. So, I have considered the longest common substring problem and the python implementation searching for a solution.