Adding signed Assembly to nHibernate
I'm working with nHibernate.
I have make an Assembly (ex : DAL.dll), which contains the mapping files (.hbm.xml) and the entities (.cs). This Assembly has a strong name (signed).
I created a console project开发者_StackOverflow社区, which reference the DAL assembly (DAL.dll).
When I try to instanciate the Configuration, it fails when loading my DAL Assembly.
The error is the following :
NHibernate.MappingException: Could not compile the mapping document: DAL.Mappings.Cat.hbm.xml NHibernate.MappingException: persistent class DAL.Cat, DAL not found
This is the console application code :
Configuration cfg = new Configuration();
cfg.SetProperty(Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver");
cfg.SetProperty(Environment.ConnectionString, dsn);
cfg.SetProperty(Environment.Dialect, typeof(MsSql2005Dialect).AssemblyQualifiedName);
cfg.SetProperty(Environment.ProxyFactoryFactoryClass, typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedName);
cfg.SetProperty(Environment.ShowSql, "true");
cfg.SetProperty(Environment.ConnectionProvider, typeof(DriverConnectionProvider).AssemblyQualifiedName);
cfg.AddAssembly(typeof(DAL).Assembly);
The problem is that the hbm.xml files are referencing the entities like that :
<class name="DAL.Cat,DAL">
Is there another solution than referencing each class with their full name (with the key, etc.)
Thanks !
A slightly cleaner way of specifying the mappings that can help you is:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="DAL"
assembly="DAL assembly fully qualified name">
<class name="Cat">
...
However, this should work even if the assembly name is not qualified. Try different combinations and see what happens.
精彩评论