Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate Validator throws System.NotSupportedException after upgrading to 3.1

Has anyone encountered this?

After upgrading to NHibernate 3.1, I am receiving the following exception from NHibernate Validator when running NUnit test cases:

System.NotSupportedException : The invoked member is not supported in a dynamic assembly. at System.Reflection.Emit.InternalAssemblyBuilder.GetManifestResourceStream(String name) at NHibernate.Validator.Cfg.XmlMappingLoader.AddResource(Assembly assembly, String resource) at NHibernate.Validator.Cfg.XmlMappingLoader.GetXmlMappingFor(Type type) at NHibernate.Validator.Engine.JITClassMappingFactory.GetExternalDefinitionFor(Type type) at NHibernate.Validator.Engine.JITClassMappingFactory.GetClassMapping(Type clazz, ValidatorMode mode) at NHibernate.Validator.Engine.ClassValidator.InitValidator(Type clazz, IDictionary`2 nestedClassValidators) at NHibernate.Validator.Engine.ClassValidator..ctor(Type clazz, IConstraintValidatorFactory constraintValidatorFactory, IDictionary`2 childClassValidators, IClassValidatorFactory factory) at NHibernate.Validator.Engine.StateFullClassValidatorFactory.GetRootValidator(Type type) at NHibernate.Validator.Engine.ValidatorEngine.GetClassValidator(Type entityType) at NHibernate.Validator.Engine.ValidatorEngine.GetElementOrNew(Type entityType) at NHibernate.Validator.Engine.ValidatorEngine.InternalValidate(Object entity, Object[] activeTags) at NHibernate.Validator.Engine.ValidatorEngine.Validate(Object entity, Object[] activeTags) at NHibernate.Validator.Event.ValidateEventListener.Validate(Object entity, EntityMode mode) at NHibernate.Validator.Event.ValidatePreUpdateEventListener.OnPreUpdate(PreUpdateEvent event) at NHibernate.Action.EntityUpdateAction.PreUpdate() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Action\EntityUpdateAction.cs: line 200 at NHibernate.Action.EntityUpdateAction.Execute() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Action\EntityUpdateAction.cs: line 58 at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs: line 136 at NHibernate.Engine.ActionQueue.ExecuteActions(IList list) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs: line 126 at NHibernate.Engine.ActionQueue.ExecuteActions() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\ActionQueue.cs: line 170 at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs: line 241 at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Event\Default\DefaultFlushEventListener.cs: line 19 at NHibernate.Impl.SessionImpl.Flush() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionImpl.cs: line 1472 at TestDataAccess.FooTest.TestFoo() in FooTest.cs

As you can see from the stack trace, the error occurs when the session is flushed and NHibernate Validator does its thing.

Update I have tried stepping through the NH Validator code and it appears that at some point it is trying to validate the Castle proxy of an entity, rather than the underlying entity itself. This then causes the trouble. No idea what to do about this...

Update The problem goes away if I use the LinFu ProxyFactoryFactory, rather than Castle. Unfortunately, LinFu is giving me other problems so I don't want to use it.

like image 576
cbp Avatar asked Nov 07 '11 04:11

cbp


1 Answers

NHibernate 3.2 removed the need for external proxy libraries.

They are still supported, but they are not distributed anymore, and the default is to use an internal implementation.

Have you tried upgrading?


Update: in order to compile NHibernate Validator for NH 3.2, you need to modify NHibernateHelper as follows:

public static bool IsProxyFactoryConfigurated()
{
    var f = NHibernate.Cfg.Environment.BytecodeProvider.ProxyFactoryFactory;
    return f != null;
}

For details, read NHV-116

like image 112
Diego Mijelshon Avatar answered Nov 07 '22 04:11

Diego Mijelshon