I am trying to get an MSTest unit test running, and I have the following line in my NHibernate config section in App.config
:
<property name="proxyfactory.factory_class">NHibernate.ByteCode.DefaultProxyFactoryFactory, NHibernate</property>
Whenever I try and run the unit test, I get an exception in the ClassInitialize
method for the test ficture. The exception is:
NHibernate.Bytecode.UnableToLoadProxyFactoryFactoryException: Unable to load type 'NHibernate.ByteCode.DefaultProxyFactoryFactory, NHibernate.Bytecode' during configuration of proxy factory class.
and my initializer code is:
private static ISessionFactory _sessionFactory;
private static Configuration _configuration;
[ClassInitialize()]
public static void ProductRepositoryInitialize(TestContext testContext)
{
_configuration = new Configuration();
_configuration.Configure();
_configuration.AddAssembly(typeof(Product).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();
}
Yet the DefaultProxyFactoryFactory
is available, as I can instantiate in in a console application using the line:
NHibernate.Bytecode.DefaultProxyFactoryFactory factory = new DefaultProxyFactoryFactory();
So why is NHibernate failing to instantiate, or even find, this type in my unit test class. Is it perhaps the test class initializer is static?
BREAKING NEWS: If I use the same proxy factory but with fluent configuration, I get happiness and joy, and rows inserted into my data store.
_factory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2012)
.Mappings(m => m.HbmMappings.AddFromAssemblyOf<Product>())
.ProxyFactoryFactory<DefaultProxyFactoryFactory>()
.BuildSessionFactory();