Exception Details:
NHibernate.Cfg.HibernateConfigException: An exception occurred during configuration of persistence layer. ---> System.IO.FileNotFoundException: Could not find file 'C:\Windows\system32\Config\hibernate.cfg.xml'.
Reason:
By default window services set the default directory to the %WINDIR%$\system32. We need to change out default service's directory to wherever our service running.
---Solution 1---
Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
---Solution 2---
string configPath = ConfigurationManager.AppSettings["HibernateConfigPath"]; string path = configPath; if (!Path.IsPathRooted(configPath)) { string basedir = AppDomain.CurrentDomain.BaseDirectory; path = Path.Combine(basedir, configPath); } //we can get the correct path in 'pathToUse'