NHibernate Validator throws System.NotSupportedException after upgrading to 3.1
Asked Answered
W

1

6

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.

Winch answered 7/11, 2011 at 4:50 Comment(0)
H
1

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

Habitant answered 10/11, 2011 at 21:30 Comment(4)
NHibernate Validator is built against 3.1 and has a couple of compilation errors if I try building it against 3.2. Like I said though, the problem goes away if I build against the LinFu proxy provider, and the new NH inbuilt provider is built off LinFu, so I suspect the problem will go away. But the LinFu proxy is giving me other problems, and even tho we don't need the Castle proxy provider it's my understanding that we should still have the choice to use it if we want.Winch
Well, what are those compilation errors? It can sure be fixed.Habitant
I downloaded NHibernate.Validator and fixed the compilation error, added the change to the answer.Habitant
Hi, thanks, I tried upgrading to 3.2 then using NHibernate.Bytecode.DefaultProxyFactoryFactory and received the same exception.Winch

© 2022 - 2024 — McMap. All rights reserved.