Hi.
I have a problem using NHibernate in Windows Service.
I have created two classes:
1. NHLogEntry
2. LogWriter
NHLogEntry is a persistent class and therefore has its own mapping info. The NHLogEntry.hbm.xml is located in the same assembly as the NHLogEntry belongs to.
LogWriter stores instances of NHLogEntry into a database via NHibernate. LogWriter lives in its own assembly apart from the NHLogEntry.
I have also created a unit test for the NUnit which tests whether the work gets done correctly.
As long as I use LogWriter and NHLogEntry in a unit test or in any other windows application everything goes OK.
But when I try to use these two in a Windows Service the NHibernate fails to Configure() by not locating info about the NHLogEntry.
Information regarding the exception I get is below.
Hibernate version: 2.0.1.4000
Mapping documents: App.Config, NHLogEntry.hbm.xml
Code between sessionFactory.openSession() and session.close():
void ILogWriter.write ( LogEntry entry ) {
this._trans = this._session.BeginTransaction();
NHLogEntry e = new NHLogEntry();
e.Entry = entry;
this._session.Save ( e );
this._trans.Commit();
}
Full stack trace of any exception that occurs:
NHibernate.Cfg.HibernateConfigException: An exception occurred during configuration of persistence layer. ---> System.IO.FileNotFoundException: Could not find file 'T:\Ice-3.3.0-VC90\bin\hibernate.cfg.xml'.
File name: 'T:\Ice-3.3.0-VC90\bin\hibernate.cfg.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlCharCheckingReader.Read()
at System.Xml.XsdValidatingReader.Read()
at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader)
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
--- End of inner exception stack trace ---
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
at NHibernate.Cfg.Configuration.Configure(XmlReader textReader)
at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig)
at NHibernate.Cfg.Configuration.Configure()
at DIAmatix.Services.Log.DAL.LogWriterDAL._initNH() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriterDAL\LogWriterDAL.cs:line 39
NHibernate.Cfg.HibernateConfigException: An exception occurred during configuration of persistence layer. ---> System.IO.FileNotFoundException: Could not find file 'T:\Ice-3.3.0-VC90\bin\hibernate.cfg.xml'.
File name: 'T:\Ice-3.3.0-VC90\bin\hibernate.cfg.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlCharCheckingReader.Read()
at System.Xml.XsdValidatingReader.Read()
at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader)
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
--- End of inner exception stack trace ---
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
at NHibernate.Cfg.Configuration.Configure(XmlReader textReader)
at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig)
at NHibernate.Cfg.Configuration.Configure()
at DIAmatix.Services.Log.DAL.LogWriterDAL._initNH() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriterDAL\LogWriterDAL.cs:line 42
at DIAmatix.Services.Log.DAL.LogWriterDAL..ctor() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriterDAL\LogWriterDAL.cs:line 63
NHibernate.Cfg.HibernateConfigException: An exception occurred during configuration of persistence layer. ---> System.IO.FileNotFoundException: Could not find file 'T:\Ice-3.3.0-VC90\bin\hibernate.cfg.xml'.
File name: 'T:\Ice-3.3.0-VC90\bin\hibernate.cfg.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlCharCheckingReader.Read()
at System.Xml.XsdValidatingReader.Read()
at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader)
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
--- End of inner exception stack trace ---
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
at NHibernate.Cfg.Configuration.Configure(XmlReader textReader)
at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig)
at NHibernate.Cfg.Configuration.Configure()
at DIAmatix.Services.Log.DAL.LogWriterDAL._initNH() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriterDAL\LogWriterDAL.cs:line 42
at DIAmatix.Services.Log.DAL.LogWriterDAL..ctor() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriterDAL\LogWriterDAL.cs:line 66
at DIAmatix.Services.Log.LogWriterIce..ctor() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriter\LogWriter.cs:line 20
10/9/2008 17:21:27:218 DIAmatixBox: error: IceBox.FailureException
reason = "ServiceManager: exception while starting service Log: NHibernate.Cfg.HibernateConfigException: An exception occurred during configuration of persistence layer. ---> System.IO.FileNotFoundException: Could not find file 'T:\Ice-3.3.0-VC90\bin\hibernate.cfg.xml'.
File name: 'T:\Ice-3.3.0-VC90\bin\hibernate.cfg.xml'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlCharCheckingReader.Read()
at System.Xml.XsdValidatingReader.Read()
at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader)
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
--- End of inner exception stack trace ---
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
at NHibernate.Cfg.Configuration.Configure(XmlReader textReader)
at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig)
at NHibernate.Cfg.Configuration.Configure()
at DIAmatix.Services.Log.DAL.LogWriterDAL._initNH() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriterDAL\LogWriterDAL.cs:line 42
at DIAmatix.Services.Log.DAL.LogWriterDAL..ctor() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriterDAL\LogWriterDAL.cs:line 66
at DIAmatix.Services.Log.LogWriterIce..ctor() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriter\LogWriter.cs:line 23
at DIAmatix.Services.Log.LogWriterBox.IceBox.ServiceOperationsNC_.start(String name, Communicator communicator, String[] args) in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriter\LogWriter.cs:line 58
at IceBox.ServiceManagerI.startService(String service, String entryPoint, String[] args) in d:\builds\distbuilds\release\Ice-3.3.0\cs\src\IceBox\ServiceManagerI.cs:line 693"
at IceBox.ServiceManagerI.startService(String service, String entryPoint, String[] args) in d:\builds\distbuilds\release\Ice-3.3.0\cs\src\IceBox\ServiceManagerI.cs:line 706
at IceBox.ServiceManagerI.load(String name, String value) in d:\builds\distbuilds\release\Ice-3.3.0\cs\src\IceBox\ServiceManagerI.cs:line 489
at IceBox.ServiceManagerI.run() in d:\builds\distbuilds\release\Ice-3.3.0\cs\src\IceBox\ServiceManagerI.cs:line 338
Caused by: NHibernate.Cfg.HibernateConfigException: An exception occurred during configuration of persistence layer.
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
at NHibernate.Cfg.Configuration.Configure(XmlReader textReader)
at NHibernate.Cfg.Configuration.Configure(String fileName, Boolean ignoreSessionFactoryConfig)
at NHibernate.Cfg.Configuration.Configure()
at DIAmatix.Services.Log.DAL.LogWriterDAL._initNH() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriterDAL\LogWriterDAL.cs:line 42
at DIAmatix.Services.Log.DAL.LogWriterDAL..ctor() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriterDAL\LogWriterDAL.cs:line 66
at DIAmatix.Services.Log.LogWriterIce..ctor() in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriter\LogWriter.cs:line 23
at DIAmatix.Services.Log.LogWriterBox.IceBox.ServiceOperationsNC_.start(String name, Communicator communicator, String[] args) in T:\work\DIAmatixServices\trunk\src\dotnet\services\log\LogWriter\LogWriter.cs:line 58
at IceBox.ServiceManagerI.startService(String service, String entryPoint, String[] args) in d:\builds\distbuilds\release\Ice-3.3.0\cs\src\IceBox\ServiceManagerI.cs:line 693
Caused by: System.IO.FileNotFoundException: Could not find file 'T:\Ice-3.3.0-VC90\bin\hibernate.cfg.xml'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlCharCheckingReader.Read()
at System.Xml.XsdValidatingReader.Read()
at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space)
at System.Xml.XPath.XPathDocument..ctor(XmlReader reader)
at NHibernate.Cfg.ConfigurationSchema.HibernateConfiguration..ctor(XmlReader hbConfigurationReader, Boolean fromAppSetting)
Name and version of the database you are using: Microsoft SQL Server 2008
|