由于代码和配置文件同时配置了 assembly 导致了这个错误。
if (string.IsNullOrEmpty(ConfigurationFileName)) throw new ArgumentException("ConfigurationFileName property was blank"); NhConfigurationInstance = new Configuration(); NhConfigurationInstance.Configure(ConfigurationFileName); NhConfigurationInstance.AddAssembly(typeof(Customer).Assembly); return NhConfigurationInstance;
而配置文件则如下:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NHibernate.Test">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">User ID=scott;Password=123456;Data Source=fortest</property>
<property name="show_sql">false</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="hbm2ddl.keywords">none</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache" >true</property>
<property name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider</property>
<mapping assembly="eDirectory.Domain"/>
</session-factory>
</hibernate-configuration>
解决办法:删除<mapping assembly="mapping assembly="eDirectory.Domain"/> 或者注释掉代码中的配置