ActiveRecord 不会从 GAC 中的程序集加载类型

发布于 2024-10-03 22:11:21 字数 1912 浏览 4 评论 0原文

我想尝试 ActiveRecord,因为它具有出色的会话/事务范围管理和良好的属性映射策略。我通常使用 Nhibernate + Fluent Nhibernate 来构建我的 DAL。

我陷入了这个奇怪的问题:ActiveRecord 不想从位于 GAC 中的程序集加载我的类型...而 FluentNhibernate 可以。 以下是失败的 ActiveRecord 初始化代码:

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

ActiveRecordStarter.Initialize( 来源, 类型(人), 类型(汽车) );

包含“Person”和“Car”的程序集位于 GAC 中,而 Fluent Nhibernate 可以加载它(即使在惰性集合中), ActiveRecord 无法加载并引发以下异常:

à NHibernate.Cfg.XmlHbmBinding.Binder.ClassForFullNameChecked(String fullName, String errorMessage) à NHibernate.Cfg.XmlHbmBinding.Binder.ClassForNameChecked(String name, Mappings 映射, String errorMessage) à NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindClass(XmlNode 节点, IDecoratable classMapping, PersistentClass 模型, IDictionary2heritedMetas) à NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode 节点, HbmClass classSchema, IDictionary2继承的Metas) à NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNodeparentNode, IDictionary`2heritedMetas) à NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode 节点) à NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)

持久类 CFM.SearchServices.Finder.DAL.Entities.Person,未找到 CFM.SearchServices.Finder

有什么方法可以强制 ActiveRecord 提供 NHibernate 完全限定名称吗?

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, IDictionary
2 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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弄潮 2024-10-10 22:11:21

不幸的是,目前 ActiveRecord 正在显式生成没有版本和公钥信息的类型名称,正如您在此处的 MakeTypeName() 方法的源代码中看到的那样:
https:/ /github.com/castleproject/Castle.ActiveRecord/blob/master/src/Castle.ActiveRecord/Framework/Internal/Visitors/XmlGenerationVisitor.cs#L1398

您当然可以创建自己的 ActiveRecord 版本,该版本完全创建限定类型名称,请在 https://github.com/castleproject/Castle.ActiveRecord 下载源代码/archives/master,
修改 MakeTypeName() 方法以创建完全限定的类型名称并重建/运行测试。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文