The type name or alias could not be resolved

Nov 3, 2010 at 10:17 AM

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
  <alias alias="Singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity"/>
  <alias alias="Transient" type="Microsoft.Practices.Unity.TransientLifetimeManager, Microsoft.Practices.Unity"/>
  <alias alias="IBootstrapperTask" type="Yankee.Infrastructure.IBootstrapperTask, Yankee.Core"/>
  <alias alias="IControllerFactory" type="System.Web.Mvc.IControllerFactory, System.Web.Mvc, Version=2.0.0.0, Culture=neutral,PublickeyToken=31bf3856ad364e35"/>
  <alias alias="ControllerFactory" type="Yankee.YYSports.Web.ControllerFactory, Yankee.YYSports.Web"/>
  <alias alias="RegisterControllerFactory" type="Yankee.YYSports.Web.RegisterControllerFactory, Yankee.YYSports.Web"/>
  <container name="MyContainer">
    <register name="registerControllerFactory" type="IBootstrapperTask" mapTo="RegisterControllerFactory">
      <lifetime type="Singleton"/>
      <constructor>
        <param name="controllerFactory" type="IControllerFactory" dependencyType="IControllerFactory">
        </param>
      </constructor>
    </register>
  </container>
</unity>

The type name or alias RegisterControllerFactory could not be resolved. Please check your configuration file and verify this type name.

说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.InvalidOperationException: The type name or alias RegisterControllerFactory could not be resolved. Please check your configuration file and verify this type name.

源错误:

行 19:         {
行 20: UnityConfigurationSection configuration = (UnityConfigurationSection) ConfigurationManager.GetSection("unity");
行 21: //configuration.Containers.Default.Configure(_container);
行 22: configuration.Configure(_container, "MyContainer");
行 23: }

Nov 4, 2010 at 12:39 AM
Edited Nov 4, 2010 at 4:50 AM

Are you sure you entered the correct type name for the RegisterControllerFactory?  In addition, the constructor injection for RegisterControllerFactory defines a parameter with dependencyType equal to IControllerFactory but there's no configured registration for this type.  You should map the IControllerFactory to a specific implementation.

I also have some suggestions:

I noticed you defined aliases Singleton and Transient.  You can remove these aliases and make use of Unity 2.0's pre-defined aliases singleton and transient (lower-case).

You can also use this method of loading the container from the configuration file instead of using the UnityConfigurationSection.Configure API:

IUnityContainer container = new UnityContainer();

container.LoadConfiguration("MyContainer");

Make sure to add a using statement for Microsoft.Practices.Unity.Configuration namespace.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com