PDA

View Full Version : Reading configuration when running as a windows service


Hussam
06-28-2007, 09:18 AM
Hi,

I have a remoting library that is built on spring and has been hosted inside a console application. I wanted to host it inside a windows service now.
I established a usual .Net Win Service and added the configuration nodes exactly as they were in the configuration of the console application.

The problem is that reading the configuration results in an error with the following stack:

at System.Configuration.BaseConfigurationRecord.Evalu ateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evalu ate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ction(String configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSe ction(String configKey)
at System.Configuration.ClientConfigurationSystem.Sys tem.Configuration.Internal.IInternalConfigSystem.G etSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSecti on(String sectionName)
at Spring.Util.ConfigurationUtils.GetSection(String sectionName)
at Spring.Context.Support.ContextRegistry.InitializeC ontextIfNeeded()
at Spring.Context.Support.ContextRegistry.GetContext( )
at Enterprise.ApplicationConfiguration..ctor()

I refer to the configuration of the objects as: <resource uri="file://~/SpringMiddlewareConfig.xml"/>

I tried also to run the sam code as a console application with the same configuration settings and it functioned well. My question is: am I missing something essential? or have I misunderstood something here?

Regards
Hussam

Bruno Baia
06-28-2007, 09:46 AM
Hi,

It seems this is a bug.
~ is not resolved as the base directory in a windows service.
Have you tried file://SpringMiddlewareConfig.xml or using the full path ?

Bruno

Hussam
06-28-2007, 10:43 AM
Hi and thanks for your reply
using file://myfile.xml does not help. This will will end up in the C:\windows directiory and file not found exception.

In contrary using absolute paths does the work...but it is not a good way of refering to files.... Well, well, We know now about the problem :)

Thanks for your time
hussam