Search code examples
nhibernateactiverecordcastle-activerecord

ActiveRecord won't load types from an assembly in GAC


I'd like to experiment with ActiveRecord for its great session/transaction scope management and its good attributes mapping strategy. I usually use Nhibernate + Fluent Nhibernate to build my DAL.

I'm stuck into that strange problem : ActiveRecord doesn't want to load my types from an assembly that is located in GAC... while FluentNhibernate can. Here is the ActiveRecord Initialization code that fails :

IDictionary properties = new Dictionary(); properties.Add("connection.driver_class", "NHibernate.Driver.SqlClientDriver"); properties.Add("dialect", "NHibernate.Dialect.MsSql2005Dialect"); properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider"); properties.Add("connection.connection_string", "MY_CONNECTION_STRING"); properties.Add("proxyfactory.factory_class", typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedName); InPlaceConfigurationSource source = new InPlaceConfigurationSource(); source.Add(typeof(ActiveRecordBase), properties);

ActiveRecordStarter.Initialize( source, typeof(Person), typeof(Car) );

The assembly that contains "Person" and "Car" is in GAC, while Fluent Nhibernate can load it (even in lazy collections), ActiveRecord can't load and throws the following exception :

à NHibernate.Cfg.XmlHbmBinding.Binder.ClassForFullNameChecked(String fullName, String errorMessage) à NHibernate.Cfg.XmlHbmBinding.Binder.ClassForNameChecked(String name, Mappings mappings, String errorMessage) à NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindClass(XmlNode node, IDecoratable classMapping, PersistentClass model, IDictionary2 inheritedMetas) à NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node, HbmClass classSchema, IDictionary2 inheritedMetas) à NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode parentNode, IDictionary`2 inheritedMetas) à NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node) à NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)

persistent class CFM.SearchServices.Finder.DAL.Entities.Person, CFM.SearchServices.Finder not found

Any way to force ActiveRecord to give NHibernate fully qualified names ?


Solution

  • Unfortunately no, at the moment ActiveRecord is explicitly generating the type names without version and public key information, as you can see in the source of the MakeTypeName() method here: https://github.com/castleproject/Castle.ActiveRecord/blob/master/src/Castle.ActiveRecord/Framework/Internal/Visitors/XmlGenerationVisitor.cs#L1398

    You can of course just create your own build of ActiveRecord that creates fully qualified type names, download the source at https://github.com/castleproject/Castle.ActiveRecord/archives/master, modify the MakeTypeName() method to create fully qualified type names and rebuild/run the tests.