0
我有一個基於.Net的命令行應用程序與PostgreSQL 9.1交互(CRUD)。使用Nuget,該項目目前引用NHibernate 3.2.0.4000和FluentHibenrate 1.3.0.717NHibernate在單聲道下拋出TypeLoadException
現在代碼在.Net環境(意思是Windows Xp/7)下運行良好,但是在Mono下(Mono JIT編譯器版本2.10.8.1(Debian 2.10.8.1-1ubuntu2.2)),我看到在NHibernate中的TypeLoadException從完全相同的代碼(我沒有重新編譯任何單聲道。)。有人可以幫忙指點嗎?謝謝!
這裏是堆棧跟蹤
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> NHibernate.MappingException: Could not compile the mapping document: (XmlDocument) ---> System.TypeInitializationException: An exception was thrown by the type initializer for NHibernate.Dialect.Dialect ---> System.TypeLoadException: Could not load type 'NHibernate.Dialect.Dialect+NoOpViolatedConstraintNameExtracter' from assembly 'NHibernate, Version=3.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'.
--- End of inner exception stack trace ---
at NHibernate.Cfg.Configuration.AddDeserializedMapping (NHibernate.Cfg.MappingSchema.HbmMapping mappingDocument, System.String documentFileName) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at NHibernate.Cfg.Configuration.LogAndThrow (System.Exception exception) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddDeserializedMapping (NHibernate.Cfg.MappingSchema.HbmMapping mappingDocument, System.String documentFileName) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddValidatedDocument (NHibernate.Cfg.NamedXmlDocument doc) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.ProcessMappingsQueue() [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddDocumentThroughQueue (NHibernate.Cfg.NamedXmlDocument document) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddXmlReader (System.Xml.XmlReader hbmReader, System.String name) [0x00000] in <filename unknown>:0
at NHibernate.Cfg.Configuration.AddInputStream (System.IO.Stream xmlInputStream, System.String name) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() [0x00000] in <filename unknown>:0
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() [0x00000] in <filename unknown>:0
at MyProj.Repository.FluentNHibernateHelperPostgreSQL.CreateSessionFactory() [0x00000] in <filename unknown>:0
at MyProj.Repository.FluentNHibernateHelperPostgreSQL.get_SessionFactory() [0x00000] in <filename unknown>:0
at MyProj.Repository.FluentNHibernateHelperPostgreSQL.OpenSession() [0x00000] in <filename unknown>:0
at MyProj.Repository.NHibernateSessionHelper.SmartSessionFactory() [0x00000] in <filename unknown>:0
at MyProj.Repository.NHibernateSessionHelper.DoAnything (MyProj.Repository.TargetMethod target) [0x00000] in <filename unknown>:0
at MyProj.Program+<>c__DisplayClass10.<RetrieveDataDriver>b__a() [0x00000] in <filename unknown>:0
下面是FluentNHibernateHelperPostgreSQL.CreateSessionFactory()
private static ISessionFactory CreateSessionFactory()
{
FluentConfiguration fluentConfiguration = Fluently.Configure();
PostgreSQLConfiguration standard = PostgreSQLConfiguration.Standard;
FluentConfiguration fluentConfiguration1 = fluentConfiguration.Database(((PersistenceConfiguration<PostgreSQLConfiguration, PostgreSQLConnectionStringBuilder>)standard).ConnectionString((PostgreSQLConnectionStringBuilder c) => c.FromConnectionStringWithKey("ConnectionStringKey")));
ISessionFactory sessionFactory = fluentConfiguration1.Mappings((MappingConfiguration m) => m.AutoMappings.Add(FluentNHibernateHelperPostgreSQL.CreateAutomappings)).ExposeConfiguration(FluentNHibernateHelperPostgreSQL.BuildSchema).BuildSessionFactory();
return sessionFactory;
}
它看起來像你的一個映射文檔引用了Mono無法找到的類型。如果你在nHibernate中有log4net配置,你應該能夠看到關於什麼文檔和它試圖加載的類型的更多細節。爲此,請將log4net appenders添加到您的配置文件中,如http://nhforge.org/wikis/howtonh/configure-log4net-for-use-with-nhibernate.aspx中所述,然後記得調用log4net.Config.XmlConfigurator()在嘗試創建sessionfactory前 – jakobandersen
我能夠讓log4net生成日誌。但是,它尚未確定確切原因。無論哪種情況,log4net都顯示代碼能夠生成 xml blob。唯一的區別是Windows輸出'2012-09-18 01:18:27,508 [1] INFO NHibernate.Dialect.Dialect - 使用方言:NHibernate.Dialect.PostgreSQLDialect'而單聲道輸出'2012-09-18 01:03 :31,529 [1] ERROR NHibernate.Cfg.Configuration - 無法編譯映射文檔:(XmlDocument)' 我需要再次使用log4net來查看它是否可以生成更深入的日誌 –
Antony
我會測試與單聲道2.11.4 – knocte