By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Reading app.config from a Windows Service

P: n/a
Hi all

I have created a Service that will listen for incoming requests from client
computers and communicate with my .NET remoting objects to send data back.

My problem is when I start the Service. I call the
RemotingConfiguration.Configure("appname.exe.confi g") method, but I get a
System.IO.FileNotFoundException at that line. The file does exist in the
same directory as the Service's executable.

Is there something different I need to know about when using Windows
Services and app.config files? I have the same method working fine in a
regular executable, but I want to implement the Service.

I attached to the process when the service was running to step through the
code. I also tried trapping for the exception to write it to the event log,
when I step through the exception is thrown and the line that contains the
EventLog.WriteEntry is executed, but nothing appears in the event log. Also,
I have a general Catch block after the File catch block that also gets
executed, and this DOES appear in the EventLog. I though that only 1 Catch
block was executed when an error has ocurred?!?!

Here is my code, at the moment in the OnResume method as you cannot debug
the OnStart method:
RemotingConfiguration.Configure("CABSServiceContro ller.exe.config")
EventLog.WriteEntry("CABS Service is now listening for incoming
requests", EventLogEntryType.Information)

Catch FileEx As System.IO.FileNotFoundException
EventLog.WriteEntry("The specified file '" & FileEx.FileName & "'
cannot be found" _
& vbCrLf & "Stack Trace: " &
FileEx.StackTrace, EventLogEntryType.Error)
'// This gets executed but not logged
Catch Ex As Exception
EventLog.WriteEntry("A general error has occurred." _
& vbCrLf & "Source: " & Ex.Source _
& vbCrLf & "Message: " & Ex.Message _
& vbCrLf & "Stack Trace: " &
Ex.StackTrace, EventLogEntryType.Error)
'// This also gets executed but DOES get logged
End Try

If anyone has any insight into this I would be very grateful.

Kind Regards,
Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a

Steve, when your app is running as a windows service, it's actually
running in the System32 folder, and not in the directory where it was
installed (ie: c:\program files\AppName\).

That's why you're getting a File Not Found error.

Hope that helps.

- Eric
Posted via
View this thread:

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.