简体   繁体   中英

Nhibernate Validator

In my unit tests I am getting an error when I am debugging. The weird thing is I do not get this whenever I just run the test (it's only when debugging a test). I get an exception whenever I try to validate one of my entities with NHibernate Validator. The following line throws the exception below.

InvalidValue[] invalidValues = validatorEngine.Validate(group);

Exception: The ProxyFactoryFactory was not configured. Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers. Example: NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu Example: NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle

I'm configuring the validator engine like this:

var nhvConfiguration = new FluentConfiguration();
        nhvConfiguration
           .SetDefaultValidatorMode(ValidatorMode.OverrideAttributeWithExternal)
           .Register(Assembly.Load("Business.Objects")
           .ValidationDefinitions());

        validatorEngine = new ValidatorEngine();
        validatorEngine.Configure(nhvConfiguration);

I'm not sure what's going on here. Anyone know why I am getting this error while debugging and not while just running the test?

I'm using NHibernate 3.1 and NHibernate validator 1.3

I haven't used nhibernate validator before but nHibernate needs a ProxyFactory class to be specified as part of the configuration other wise it throws this sort of error

I generally use the xml mapping files and config files this is the line that I would normally add <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>

Any of the proxy factories would do. it comes down to preference.

The reason it was throwing this exception was unrelated to any nhibernate configuration. The following post explains why I was getting this exception.

C# Uncaught exception in unit test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM