0

我有一个基于 .Net 的命令行应用程序,它与 PostgreSQL 9.1 交互(CRUD)。使用 Nuget,该项目目前引用 NHibernate 3.2.0.4000 和 FluentHibenrate 1.3.0.717

现在代码在 .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;
  }
4

1 回答 1

1

解决方案是从 go-mono.com 手动部署最新的 Mono 包正如评论部分 knocte 所建议的那样,2.11.4解决了问题。

我还没有尝试过 3.x,但到目前为止,我对 2.11.x 很满意,还没有理由跳进 3.x 的船。

于 2013-02-08T19:44:51.257 回答