Nhibernate Validator

不打扰是莪最后的温柔 提交于 2019-12-13 05:39:33

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5590130/nhibernate-validator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!