Error while creating Fluent NHibernate Session factory

fluent-nhibernatenhibernate

Does anyone have any experience with the following fluent config error?

faultString = "An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

I have no problems on my development box, but when the dlls are put up on the production server and tested, the error occurs.

The development box is pointing at the same database so I don't think differences in schema are the issue.

Also, does any one know if there is any documentation for fluent nhibernate?

Any pointers much appreciated.

Here is the inner exception thrown:

System.TypeInitializationException: The type initializer for 'NHibernate.ByteCode.Castle.ProxyFactory' threw an exception. ---> System.Security.SecurityException: That assembly does not allow partially trusted callers.

   at Castle.DynamicProxy.ModuleScope..ctor(Boolean savePhysicalAssembly, String strongAssemblyName, String strongModulePath, String weakAssemblyName, String weakModulePath)

   at Castle.DynamicProxy.ModuleScope..ctor(Boolean savePhysicalAssembly)

   at Castle.DynamicProxy.ProxyGenerator..ctor()

   at NHibernate.ByteCode.Castle.ProxyFactory..cctor()

The action that failed was:

LinkDemand

The Zone of the assembly that failed was:

MyComputer

   --- End of inner exception stack trace ---

   at NHibernate.ByteCode.Castle.ProxyFactory..ctor()

   at NHibernate.ByteCode.Castle.ProxyFactoryFactory.BuildProxyFactory()

   at NHibernate.Tuple.Entity.PocoEntityTuplizer.BuildProxyFactoryInternal(PersistentClass class, IGetter getter, ISetter setter)

   at NHibernate.Tuple.Entity.PocoEntityTuplizer.BuildProxyFactory(PersistentClass persistentClass, IGetter idGetter, ISetter idSetter)

   at NHibernate.Tuple.Entity.AbstractEntityTuplizer..ctor(EntityMetamodel entityMetamodel, PersistentClass mappingInfo)

   at NHibernate.Tuple.Entity.PocoEntityTuplizer..ctor(EntityMetamodel entityMetamodel, PersistentClass mappedEntity)

   at NHibernate.Tuple.Entity.EntityEntityModeToTuplizerMapping..ctor(PersistentClass mappedEntity, EntityMetamodel em)

   at NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClass, ISessionFactoryImplementor sessionFactory)

   at NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory)

   at NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping)

   at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg)

   at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)

   at NHibernate.Cfg.Configuration.BuildSessionFactory()

   at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 93"
  message = "faultCode:Server.Processing faultString:'System.TypeInitializationException: The type initializer for 'NHibernate.ByteCode.Castle.ProxyFactory' threw an exception. ---> System.Security.SecurityException: That assembly does not allow partially trusted callers.

   at Castle.DynamicProxy.ModuleScope..ctor(Boolean savePhysicalAssembly, String strongAssemblyName, String strongModulePath, String weakAssemblyName, String weakModulePath)

   at Castle.DynamicProxy.ModuleScope..ctor(Boolean savePhysicalAssembly)

   at Castle.DynamicProxy.ProxyGenerator..ctor()

   at NHibernate.ByteCode.Castle.ProxyFactory..cctor()

The action that failed was:

LinkDemand

The Zone of the assembly that failed was:

MyComputer

   --- End of inner exception stack trace ---

   at NHibernate.ByteCode.Castle.ProxyFactory..ctor()

   at NHibernate.ByteCode.Castle.ProxyFactoryFactory.BuildProxyFactory()

   at NHibernate.Tuple.Entity.PocoEntityTuplizer.BuildProxyFactoryInternal(PersistentClass class, IGetter getter, ISetter setter)

   at NHibernate.Tuple.Entity.PocoEntityTuplizer.BuildProxyFactory(PersistentClass persistentClass, IGetter idGetter, ISetter idSetter)

   at NHibernate.Tuple.Entity.AbstractEntityTuplizer..ctor(EntityMetamodel entityMetamodel, PersistentClass mappingInfo)

   at NHibernate.Tuple.Entity.PocoEntityTuplizer..ctor(EntityMetamodel entityMetamodel, PersistentClass mappedEntity)

   at NHibernate.Tuple.Entity.EntityEntityModeToTuplizerMapping..ctor(PersistentClass mappedEntity, EntityMetamodel em)

   at NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClass, ISessionFactoryImplementor sessionFactory)

   at NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory)

   at NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping)

   at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg)

   at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)

   at NHibernate.Cfg.Configuration.BuildSessionFactory()

   at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 93' faultDetail:'null'"
  name = "Error"
  rootCause = (null)

FluorineStackTrace:

undefined

Best Answer

I think this is close to this question about trust:

NHibernate 2 + Fluent Nhibernate medium trust

The issue isn't about fluent NHibernate, but Castle Dynamic Proxy 2. I personally have full trust on the environments I deploy to so I haven't had to resolve it.

Your options are to:

  • Get an updated Castle Dynamic Proxy so that this is fixed.
  • Try another proxy.
  • Use the pregenerated nhibernate proxy factory.

You should be able to find posts for all of these on nhforge.org

Related Topic