Could not load type 'singleton'

Aug 3, 2009 at 4:49 PM

Hi all, I'm getting the following error when trying to resolve type "IRepositoryFactory":

Could not load type 'singleton' from assembly 'Microsoft.Practices.Unity.Configuration, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.


<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

Unity section in config:

          <type type="Infrastructure.DomainFramework.Repositories.IRepositoryFactory, Infrastructure.DomainFramework.Repositories"
                mapTo="ZZZ.ContentManagement.DomainAccess.NHibernate.NHibernateRepositoryFactory, ZZZ.ContentManagement.DomainAccess.NHibernate">
            <lifetime type="singleton" />



IRepositoryFactory factory = Unity.Container.Resolve<IRepositoryFactory>();


This is running in a TestProject, .NET 3.5, latest version of Unity.

Any ideas?


Aug 4, 2009 at 3:13 AM

You should have defined the "singleton" alias by adding

<typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />

in the <typeAliases> section outside the <containers> section.  Or, you could specify the full type name in the type attribute of the lifetime element.

<lifetime type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Aug 4, 2009 at 8:41 AM

Ah. I didn't understand that from the source-schema explanation, though now I can see it is implicitly shown.

Many thanks