Windows服务和Nhibernate

时间:2010-10-14 19:54:25

标签: nhibernate fluent-nhibernate windows-services

我有一个有定时器的Windows服务,在timer_Elapsed事件处理程序中,将调用来自另一个组件的方法,该方法应该查看db并获取或更新一些记录。此过程将每2分钟发生一次。我使用过nhibernate用于组件中的数据访问。当我从单元测试运行该方法时它工作正常,这意味着配置和映射是正确的,但从Windows服务我得到这个例外:

FluentNHibernate.Cfg.FluentConfigurationException was caught
  Message="An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.\r\n\r\n"
  Source="FluentNHibernate"
  StackTrace:
       at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 121
 InnerException: NHibernate.MappingException
       Message="Could not configure datastore from input stream (XmlDocument)"
       Source="NHibernate"
       StackTrace:
            at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
            at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
            at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc, String name)
            at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc)
            at FluentNHibernate.PersistenceModel.Configure(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\PersistenceModel.cs:line 265
            at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentMappingsContainer.cs:line 141
            at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\MappingConfiguration.cs:line 64
            at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 112
       InnerException: System.TypeInitializationException
            Message="The type initializer for 'NHibernate.Util.TypeNameParser' threw an exception."
            Source="NHibernate"
            TypeName="NHibernate.Util.TypeNameParser"
            StackTrace:
                 at NHibernate.Util.TypeNameParser.Parse(String type, String defaultNamespace, String defaultAssembly)
                 at NHibernate.Cfg.ClassExtractor.ClassEntry..ctor(String extends, String className, String entityName, String assembly, String namespace)
                 at NHibernate.Cfg.ClassExtractor.GetClassEntries(XmlDocument document)
                 at NHibernate.Cfg.MappingsQueue.AddDocument(NamedXmlDocument document)
                 at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document)
                 at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name)
                 at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
            InnerException: System.Threading.ThreadAbortException
                 Message="Exception of type 'System.Threading.ThreadAbortException' was thrown."
                 InnerException: 

以下是timer_elapsed事件处理程序中的代码:

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)


   {
        lock (processLock)
        {
            DoWorkComponent component= new DoWorkComponent ();
            component.DoWorkMethod();
        }
    }

有人知道如何解决这个问题吗?我需要设置不同的设置吗?

先谢谢,

萨沙

1 个答案:

答案 0 :(得分:0)

问题解决了。该错误与运行该帐户的用户帐户有关 服务:

http://groups.google.ca/group/fluent-nhibernate/browse_thread/thread/bafd5dddea909eb?hl=en

谢谢, 萨沙