Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity loadConfiguration failing

I have the following unity construct method:

public static IUnityContainer CreateContainer()
{
    UnityContainer container = new UnityContainer();
    container.LoadConfiguration();

    .......
}

Then an interface, and an implementation class:

namespace MyCompany.Web.Areas.MyApp.Common
{
    public interface ISession
    {
    }
}

namespace MyCompany.Web.Areas.MyApp.Common
{
    public class SessionHandler : ISession
    {
    }
}

Instead of doing this:

Container.RegisterType<ISession, SessionHandler>(new ContainerControlledLifetimeManager()) ;

I want to use container.LoadConfiguration() to load the above RegisterType config from the web.config. BUT it doesn't seem to work

web.config:

  <unity>
    <containers>
      <container>
        <types>

          <type type="MyCompany.Web.Areas.MyApp.Common.ISession" mapTo="MyCompany.Web.Areas.MyApp.Common.SessionHandler">
            <lifetime type="singleton"/>
          </type>
        </types>
      </container>
    </containers>
  </unity>

Exception:

The type name or alias MyProject.Web.Areas.MyApp.Common.ISession could not be resolved. Please check your configuration file and verify this type name.

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.InvalidOperationException: The type name or alias MyProject.Web.Areas.MyApp.Common.ISession could not be resolved. Please check your configuration file and verify this type name.

Source Error:

Line 33: { Line 34: UnityContainer container = new UnityContainer(); Line 35: container.LoadConfiguration(); Line 36: Line 37: //container.RegisterType(new ContainerControlledLifetimeManager());

Stack Trace:

[InvalidOperationException: The type name or alias MyProject.Web.Areas.MyApp.Common.ISession could not be resolved. Please check your configuration file and verify this type name.] Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolverImpl.ResolveType(String typeNameOrAlias, Boolean throwIfResolveFails) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\ConfigurationHelpers\TypeResolverImpl.cs:110 Microsoft.Practices.Unity.Configuration.ConfigurationHelpers.TypeResolver.ResolveType(String typeNameOrAlias) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\ConfigurationHelpers\TypeResolver.cs:47 Microsoft.Practices.Unity.Configuration.RegisterElement.GetRegisteringType() in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\RegisterElement.cs:121 Microsoft.Practices.Unity.Configuration.RegisterElement.ConfigureContainer(IUnityContainer container) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\RegisterElement.cs:88 Microsoft.Practices.Unity.Configuration.ContainerConfiguringElement.ConfigureContainerInternal(IUnityContainer container) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\ContainerConfiguringElement.cs:43 Microsoft.Practices.Unity.Configuration.<>c__DisplayClass1.b__0(ContainerConfiguringElement element) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\ContainerElement.cs:114 Microsoft.Practices.ObjectBuilder2.EnumerableExtensions.ForEach(IEnumerable1 sequence, Action1 action) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Utility\EnumerableExtensions.cs:36 Microsoft.Practices.Unity.Configuration.ContainerElement.ConfigureContainer(IUnityContainer container) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\ContainerElement.cs:110 Microsoft.Practices.Unity.Configuration.UnityConfigurationSection.Configure(IUnityContainer container, String configuredContainerName) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\UnityConfigurationSection.cs:151 Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(IUnityContainer container, UnityConfigurationSection section, String containerName) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\UnityContainerExtensions.cs:37 Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(IUnityContainer container) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity.Configuration\Src\UnityContainerExtensions.cs:64 MyProject.Web.ApplicationContainer.CreateContainer() in C:\Workspace\MCDev\MyApp\MyApp\MyProject.Web\ApplicationContainer.cs:35 MyProject.Web.ApplicationContainer.Initialize(HttpContext context) in C:\Workspace\MCDev\MyApp\MyApp\MyProject.Web\ApplicationContainer.cs:53 MyProject.Web.MvcApplication.Application_Start() in C:\Workspace\MCDev\MyApp\MyApp\MyProject.Web\Global.asax.cs:41

like image 302
FaNIX Avatar asked Oct 04 '11 23:10

FaNIX


1 Answers

I don't think it knows what dll to look in:

<unity>
    <containers>
      <container>
        <types>
          <type type="MyCompany.Web.Areas.MyApp.Common.ISession, MyCompany" mapTo="MyCompany.Web.Areas.MyApp.Common.SessionHandler, MyCompany">
            <lifetime type="singleton"/>
          </type>
        </types>
      </container>
    </containers>
  </unity>
like image 133
rick schott Avatar answered Oct 07 '22 00:10

rick schott